Skip to content

Commit

Permalink
- New type: boolean to create random boolean values as true or `f…
Browse files Browse the repository at this point in the history
…alse`

- New type: `boolean-digit` to create random boolean values as `1` or `0`
- New type: `datetime-iso` to create ISO8601 formatted dates
- Added separators to the `words()` method
- Build Updates
- Github actions updates
- ColdBox 7 auto testing
- Markdown linting
- Added more random data
  • Loading branch information
lmajano committed May 9, 2024
1 parent 5b535fd commit ad2a592
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 15 deletions.
5 changes: 5 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

- New type: `boolean` to create random boolean values as `true` or `false`
- New type: `boolean-digit` to create random boolean values as `1` or `0`
- New type: `datetime-iso` to create ISO8601 formatted dates
- Added separators to the `words()` method
- Build Updates
- Github actions updates
- ColdBox 7 auto testing
- Markdown linting
- Added more random data

## [3.6.0] => 2022-SEP-22

Expand Down
94 changes: 79 additions & 15 deletions models/MockData.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -64,23 +64,40 @@ component {
];

variables._lastNames = [
"Allen",
"Anderson",
"Bearenstein",
"Boudreaux",
"Brown",
"Camden",
"Castro",
"Clapton",
"Clark",
"Davis",
"Degeneres",
"Elias",
"Flores",
"Garcia",
"Hall",
"Harris",
"Hill",
"Jackson",
"Johnson",
"Jones",
"King",
"Lainez",
"Lee",
"Lewis",
"Lopez",
"Madeiro",
"Maggiano",
"Marquez",
"Martin",
"Martinez,"
"Messi",
"Miller",
"Moneymaker",
"Moore",
"Padgett",
"Pilato",
"Reyes",
Expand All @@ -92,37 +109,70 @@ component {
"Sharp",
"Smith",
"Stroz",
"Taylor",
"Thomas",
"Thompson,"
"Tobias",
"Zelda"
"Walker",
"White",
"Williams,"
"Wilson",
"Young",
"Zelda",
];

variables._webDomains = [
"adobe.com",
"amazon.com",
"aol.com",
"apple.com",
"awesome.com",
"bitbucket.org",
"box.com",
"box.io",
"box.net",
"boxing.com",
"example.sv.com",
"dropbox.com",
"ebay.com",
"email.com",
"example.co.uk",
"example.jp",
"example.edu",
"example.com",
"example.edu",
"example.jp",
"example.net",
"email.com",
"mail.io",
"example.sv.com",
"facebook.com",
"github.com",
"gmail.com",
"google.com",
"hulu.com",
"instagram.com",
"linkedin.com",
"mail.io",
"medium.com",
"microsoft.com",
"msn.com",
"ortus.io",
"netflix.com",
"ortus.com",
"sample.io",
"sample.edu",
"ortus.io",
"pinterest.com",
"quora.com",
"reddit.com",
"sample.com",
"sample.edu",
"sample.io",
"slack.com",
"snapchat.com",
"stackoverflow.com",
"test.com"
"tumblr.com",
"twitch.tv",
"twitter.com",
"udemy.com",
"wikipedia.org",
"wordpress.com",
"yahoo.com",
"zoom.us"
];

variables._loremData = "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.";
Expand All @@ -143,8 +193,11 @@ component {
"age",
"all_age",
"baconlorem",
"boolean",
"boolean-digit",
"date",
"datetime",
"datetime-iso",
"email",
"fname",
"gps",
Expand All @@ -160,6 +213,9 @@ component {
];

variables._extensions = [
".bx",
".bxs",
".bxm",
".cfm",
".css",
".doc",
Expand Down Expand Up @@ -274,6 +330,12 @@ component {
if ( arguments.type == "autoincrement" ) {
return arguments.index;
}
if ( arguments.type == "boolean" ) {
return randRange( 0, 1 ) > 0 ? true : false;
}
if ( arguments.type == "boolean-digit" ) {
return randRange( 0, 1 );
}
if ( arguments.type == "ipaddress" ) {
return ipAddress();
}
Expand Down Expand Up @@ -343,6 +405,9 @@ component {
if ( arguments.type == "datetime" ) {
return dateRange( showTime = true );
}
if ( arguments.type == "datetime-iso" ) {
return dateRange( showTime = true, dateFormat = "iso" );
}
if ( arguments.type.findNoCase( "num" ) == 1 ) {
return num(
arguments.type.find( ":" ) ? arguments.type.REreplaceNoCase( "num\:?", "" ) : javacast(
Expand Down Expand Up @@ -469,8 +534,9 @@ component {
* Generate random words
*
* @size The number of words to generate or can be a min:max range to produce random number of words
* @separator The separtor to use, defaults to empty space
*/
function words( size = 1 ){
function words( size = 1, separator = " " ){
// Do we have a random size request?
if ( find( ":", arguments.size ) ) {
arguments.size = randRange( getToken( arguments.size, 1, ":" ), getToken( arguments.size, 2, ":" ) );
Expand All @@ -484,7 +550,7 @@ component {
result.append( variables._adjectives[ randRange( 1, variables._adjectives.len() ) ] );
}
}
return result.toList( " " );
return result.toList( arguments.separator );
}

/**
Expand Down Expand Up @@ -693,14 +759,12 @@ component {
* @to The end date else defaults to today
* @showTime Show time in the data
* @dateFormat The date formatting to use
* @timeFormat The time formmating to use
*/
function dateRange(
date from = "#createDateTime( "2010", "01", "01", "0", "0", "0" )#",
date to = "#now()#",
showTime = false,
dateFormat = "medium",
timeFormat = "medium"
dateFormat = "medium"
){
var timeDifference = dateDiff( "s", arguments.from, arguments.to );
var result = dateAdd(
Expand All @@ -710,7 +774,7 @@ component {
);

if ( arguments.showTime ) {
return dateFormat( result, arguments.dateFormat ) & " " & timeFormat( result, arguments.timeFormat );
return dateTimeFormat( result, arguments.dateFormat );
} else {
return dateFormat( result, arguments.dateFormat );
}
Expand Down
3 changes: 3 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,11 @@ The available types MockDataCFC supports are:
* `all_age`: Generates a random age of 1 to 100.
* `autoincrement` : Returns an incremented index starting from 1
* `baconlorem`: Returns bacon lorem ipsum text. If used as `baconlorem:N`, returns N paragraphs. If used as `baconlorem:X:Y`, returns a random number of paragraphs between X and Y.
* `boolean`: Generates a random boolean value of `true` or `false`.
* `boolean-digit` : Generates a random boolean value as a digit of 0 or 1.
* `date`: Generates a random date
* `datetime`: Generates a random date and time value
* `datetime-iso` : Generates a random date and time value in ISO format
* `email`: Generates a random email.
* `fname`: Generates a random first name.
* `imageurl` : Generates a random image URL with a random protocol
Expand Down
15 changes: 15 additions & 0 deletions test-harness/tests/specs/MockDataTest.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,21 @@ component extends="coldbox.system.testing.BaseTestCase" appMapping="root" {
expect( r[ 1 ].createdOn ).toBeDate();
} );

it( "can generate iso date times", function(){
var r = mockDataCFC.mock( createdOn = "datetime-iso" );
expect( r[ 1 ].createdOn ).toBeDate();
} );

it( "can generate boolean randomness", function(){
var r = mockDataCFC.mock( isActive : "boolean" );
expect( r[ 1 ].isActive ).toBeBoolean();
} );

it( "can generate boolean digit randomness", function(){
var r = mockDataCFC.mock( isActive : "boolean-digit" );
expect( r[ 1 ].isActive ).toBeBoolean();
} );

it( "can generate numbers", function(){
var r = mockDataCFC.mock( value = "num" );
expect( r[ 1 ].value ).toBeNumeric().toBeLTE( 10 );
Expand Down

0 comments on commit ad2a592

Please sign in to comment.