Skip to content

Instantly share code, notes, and snippets.

@douglasrodrigo
Created October 28, 2011 01:52
Show Gist options
  • Save douglasrodrigo/1321439 to your computer and use it in GitHub Desktop.
Save douglasrodrigo/1321439 to your computer and use it in GitHub Desktop.
randexp - specs - ruby - 1.8.7
douglas@douglas-laptop:~/projetos/randexp$ rake
rake/gempackagetask is deprecated. Use rubygems/package_task instead
rake/rdoctask is deprecated. Use rdoc/task instead (in RDoc 2.4.2+)
Example disabled: should be a union between 3 sexp's
Example disabled: should return a word or a 3 digit number
Regexp#gen
- should always return a string
Randexp::Parser.parse
- should return a sexp for a non-empty string
- should return nil for an empty string
- should alias :[] to :parse
Randexp::Parser.quantify
- should return a :quantify sexp
- should push the quantify symbol on the end of the sexp
- should push the argument sexp to the first entry of the :quantify sexp
Randexp::Parser.union
- should return the union of the right-hand side if the left-hand side is nil
- should return the left-hand side if the right hand side is not present
- should append the right-hand side(s) to the left-hand side if the left-hand side is a union sexp
- should return a :union sexp between the left-hand and right-hand sexp's
Randexp::Parser.intersection
- should prepend the left-hand side onto the right-hand side :intersection sexp if the right-hand side is an :intersection sexp
- should create an :intersection sexp between the left-hand and right-hand sexp's
Randexp::Parser.random
- should return a :random sexp
- should convert the char parameter to a symbol
Randexp::Parser.literal
- should return a literal sexp
Randexp::Reducer.reduce
- should expect a sexp, and return a string
- should be an alias for :[]
Randexp::Reducer.quantify
- should call reduce with the sexp and quantity arguments as the :quantify sexp's head and tail
Randexp::Reducer.random
- should call :char with the quantity argument if the sexp's value is :w
- should call :digit with the quantity argument if the sexp's value is :d
- should call :whitespace with the quantity argument if the sexp's value is :w
- should call :randgen with the quantity argument if the sexp's value for all other cases
Randexp::Reducer.literal
- should raise an exception if the quantity argument is :+ or :'+?'
- should raise an exception if the quantity argument is :* or :'*?'
Randexp::Reducer.intersection
- should raise an exception if the quantity arguement is :+ or :'+?'
- should raise an exception if the quantity argument is :* or :'*?'
Randexp::Reducer.union
- should raise an exception if the quantity arguement is :+ or :'+?'
- should raise an exception if the quantity argument is :* or :'*?'
Randexp::Reducer.char
- should call Randgen.char if the quantity argument is :'?'
- should call Randgen.char if the quantity argument is 1
- should call Randgen.char if the quantity argument is nil
- should call Randgen.word if the quantity argument is :+
- should call Randgen.word if the quantity argument is :'+?'
- should call Randgen.word with the :length option if the quantity argument is an Integer
- should call Randgen.word with the :length option if the quantity argument is a Range
Randexp::Reducer.whitespace
- should call Randgen.whitespace if the quantity is :'?'
- should call Randgen.whitespace if the quantity is nil
- should call Randgen.whitespace quantity times if the quantity is an Integer
- should call Randgen.whitespace quantity times if the quantity is a Range
- should raise an exception if the quantity arguement is :+ or :'+?'
- should raise an exception if the quantity argument is :* or :'*?'
Randexp::Reducer.digit
- should call Randgen.digit if the quantity is :'?'
- should call Randgen.digit if the quantity is nil
- should call Randgen.digit quantity times if the quantity is an Integer
- should call Randgen.digit quantity times if the quantity is a Range
- should raise an exception if the quantity arguement is :+ or :'+?'
- should raise an exception if the quantity argument is :* or :'*?'
Randexp::Reducer.randgen
- should send Randgen the method name argument with a :length => 1 option if the quantity is :'?'
- should send Randgen the method name argument if the quantity is nil
- should send Rangen the method name argument if the quantity is 1
- should send Randgen the method name argument if the quantity is :+
- should send Randgen the method name argument if the quantity is :*
- should send Randgen the method name argument with a length option if the quantity is a Range
- should send Randgen the method name argument with a length option if the quantity is a Integer
Randexp#initialize
- should set the sexp attribute
Randexp.reduce
- should not change the original sexp in any way
Randexp#parse
- should blah
Randexp#parse ("\w")
- should be a random sexp
- should hold a word symbol
Randexp#parse ("\s")
- should be a literal sexp
- should hold a whitespace symbol
Randexp#parse ("\d")
- should be a literal sexp
- should hold a digit character
Randexp#parse ("\c")
- should be a literal sexp
- should hold a digit character
Randexp#parse ("(\w)")
- should be a random sexp
Randexp#parse ("(\w)(\d)")
- should be a union between random sexp's
Randexp#parse ("\w*")
- should be a quantify sexp and hold a random sexp
Randexp#parse ("[:sentence:]")
- should be a random sexp
Randexp#reduce
- should return a character
- should return a word
- should return a word or an empty string
- should return a word with 4 to 5 characters
- should return a digit
- should return a 2 to 10 digit number
- should return a digit or empty string
- should return a digit or a character
- should return a word or number
- should return a sentence
- should handle a telephone number
Randgen
- should generate a first name
- should generate a male first name
- should generate a female first name
- should generate a last name
- should generate a real name
- should generate a real male name
- should generate a real female name
Randgen.bool
- should return 'true' or 'false'
Randgen.lchar
- should return 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', or 'z'
Randgen.uchar
- should return 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', or 'Z'
Randgen.char
- should return 'A', 'a', 'B', 'b', 'C', 'c', 'D', 'd', 'E', 'e', 'F', 'f', 'G', 'g', 'H', 'h', 'I', 'i', 'J', 'j', 'K', 'k', 'L', 'l', 'M', 'm', 'N', 'n', 'O', 'o', 'P', 'p', 'Q', 'q', 'R', 'r', 'S', 's', 'T', 't', 'U', 'u', 'V', 'v', 'W', 'w', 'X', 'x', 'Y', 'y', 'Z', or 'z'
Randgen.whitespace
- should return '\t', '\n', '\r', or '\f'
Randgen.digit
- should return '0', '1', '2', '3', '4', '5', '6', '7', '8', or '9'
Randgen.alpha_numeric
- should return 'A', 'a', 'B', 'b', 'C', 'c', 'D', 'd', 'E', 'e', 'F', 'f', 'G', 'g', 'H', 'h', 'I', 'i', 'J', 'j', 'K', 'k', 'L', 'l', 'M', 'm', 'N', 'n', 'O', 'o', 'P', 'p', 'Q', 'q', 'R', 'r', 'S', 's', 'T', 't', 'U', 'u', 'V', 'v', 'W', 'w', 'X', 'x', 'Y', 'y', 'Z', 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', or '9'
Randgen.word
- should handle generating long strings
- should pick an entry from Dictionary
- should pick a word with a length if the length option is supplied
- should not return a string that is not a word
Randgen.first_name
- should pick a word from the female names list if the gender option is female
- should pick a word from the male names list if the gender option is male
- should pick a word from the male names list with the same length in the options
Randgen.last_name
- should pick a word from the last names list with the same length in the options
Randgen.name
- should be two words long
Randgen.email
- should pick a local-part from the dictionnary
- should use the domain option paramter
- should pick a subdomain of example.org by default
Randgen.sentence
- should be capitalized
Randgen.paragraph
- should end in a period
Randgen.phone_number
- should match /(\d{3}-)?\d{3}-\d{4}/ when no length is given
- should match /\d{3}-\d{4}/ when the length is 7
- should match /\d{3}-\d{3}-\d{4}/ when the length is 10
Finished in 1.654112 seconds
112 examples, 0 failures
********************************************************************************
Regression Specs:
- /abcd/ => 'abcd'
- /(abcd)|(defg)/ => ['abcd', 'defg']
- /(abcd)|(defg)|(hijk)/ => ['abcd', 'defg', 'hijk']
- /((abcd)|(defg))|(hijk)/ => ['abcd', 'defg', 'hijk']
- /(abcd)|((defg)|(hijk))/ => ['abcd', 'defg', 'hijk']
- /(abc)def(ghi)/ => 'abcdefghi'
- /(((abc)))/ => 'abc'
- /ab(c(def))/ => 'abcdef'
- /(\w+)/ => /\w+/
- /\w+ \w+/ => /\w+\s\w+/
- /\w*/ => /(\w+)|/
- /\w{2,5}/ => /\w{2,5}/
- /\w{1}/ => /\w/
- /\w{4}/ => /\w{4}/
- /[:word:]/ => /\w+/
- /[:bool:]/ => /true|false/
- /[:sentence:]/ => /(w+ )*/
- /[:paragraph:]/ => /( (w+ )*.)*/
- /(abc|def){1,2}/ => ['abc', 'def', 'abcabc', 'abcdef', 'defabc', 'defdef']
- /abc(def)?hij/ => /abc(def)?hij/
- /ab(c(def))?h/ => /ab(c(def))?h/
- /(\d{3}-)?\d{3}-\d{4}/ => /(\d{3}-)?\d{3}-\d{4}/
- /[:phone_number:]/ => /(\d{3}-)?\d{3}-\d{4}/
- /[:phone_number:]{7}/ => /\d{3}-\d{4}/
- /[:phone_number:]{10}/ => /\d{3}-\d{3}-\d{4}/
- /\w+@\w+\.(com|org|net)/ => /\w+@\w+\.(com|org|net)/.gen
- /\$\d{2,3}\.\d{2}/ => /\$\d{2,3}\.\d{2}/
- /[:first_name:]/ => /\w+/
- /[:last_name:]/ => /\w+/
- /[:name:]/ => /\w+ \w+/
- /[:last_name:]{5,10}/ => /\w{5,10}/
- /[:first_name:]{5,10}/ => /\w{5,10}/
Finished in 1.028339 seconds
32 examples, 0 failures
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment