Commits

Ryan Macnak committed 3835857

Convert regex tests to Minitest.

  • Participants
  • Parent commits 1e0ed35

Comments (0)

Files changed (2)

-Newspeak3
+Newspeak3
+'Regex'
+class RegexTesting usingRegex: rx minitest: minitest = (
+"Copyright (c) 2009  Ryan Macnak and other contributors.
+Licensed under the MIT license:
 
-'Regex'
+Permission is hereby granted, free of charge, to any person
+obtaining a copy of this software and associated documentation
+files (the ''Software''), to deal in the Software without
+restriction, including without limitation the rights to use,
+copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the
+Software is furnished to do so, subject to the following
+conditions:
 
-
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
 
-class RegexTesting regex: rx testFramework: utf = NewspeakObject ("Copyright (c) 2009  Ryan Macnak and other contributors.
-Licensed under the MIT license:
-
-Permission is hereby granted, free of charge, to any person
-obtaining a copy of this software and associated documentation
-files (the ''Software''), to deal in the Software without
-restriction, including without limitation the rights to use,
-copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the
-Software is furnished to do so, subject to the following
-conditions:
-
-The above copyright notice and this permission notice shall be
-included in all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED ''AS IS'', WITHOUT WARRANTY OF ANY KIND,
-EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
-OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
-HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-OTHER DEALINGS IN THE SOFTWARE."
-|
-	private TestCase = utf TestCase.
-	private rx = rx.
-|
-)
+THE SOFTWARE IS PROVIDED ''AS IS'', WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE."|
+	private TestContext = minitest TestContext.
+	private rx = rx.
+|)
+(
+class RegexTestCase = TestContext (|
+|)
+('as yet unclassified'
+test1 = (
+	assert:: rx string: 'a' matchesRegex: 'a'
+)
+test10 = (
+	assert:: rx string: 'abab' matchesRegex: '(ab)*'
+)
+test11 = (
+	deny:: rx string: 'abcab' matchesRegex: '(ab)*'
+)
+test12 = (
+	assert:: rx string: 'ac' matchesRegex: 'ab*c'
+)
+test13 = (
+	deny:: rx string: 'ac' matchesRegex: 'ab+c'
+)
+test14 = (
+	assert:: rx string: 'abbc' matchesRegex: 'ab+c'
+)
+test15 = (
+	deny:: rx string: 'abbc' matchesRegex: 'ab?c'
+)
+test16 = (
+	deny:: rx string: 'ab*' matchesRegex: 'ab*'
+)
+test17 = (
+	assert:: rx string: 'ab*' matchesRegex: 'ab\*'
+)
+test18 = (
+	assert:: rx string: 'a\c' matchesRegex: 'a\\c'
+)
+test19 = (
+	assert:: rx string: 'abb' matchesRegex: 'ab*|ba*'
+)
+test2 = (
+	assert:: rx string: 'foobar' matchesRegex: 'foobar'
+)
+test20 = (
+	assert:: rx string: 'baa' matchesRegex: 'ab*|ba*'
+)
+test21 = (
+	deny:: rx string: 'baab' matchesRegex: 'ab*|ba*'
+)
+test22 = (
+	assert:: rx string: '0' matchesRegex: '[01]'
+)
+test23 = (
+	deny:: rx string: '3' matchesRegex: '[01]'
+	)
+test24 = (
+	deny:: rx string: '11' matchesRegex: '[01]')
+test25 = (
+	assert:: rx string: '10010100' matchesRegex: '[01]+')
+test26 = (
+	deny:: rx string: '10010210' matchesRegex: '[01]+')
+test27 = (
+	deny:: rx string: '0' matchesRegex: '[^01]')
+test28 = (
+	assert:: rx string: '3' matchesRegex: '[^01]')
+test29 = (
+	assert:: rx string: 'axyzb' matchesRegex: 'a.+b')
+test3 = (
+	deny:: rx string: 'blorple' matchesRegex: 'foobar'
+)
+test30 = (
+	assert:: rx string: 'ax zb' matchesRegex: 'a.+b'
+)
+test31 = (
+	assert:: rx string: 'ax
+zb' matchesRegex: 'a.+b')
+test32 = (
+	deny:: rx string: 'abcde' matchesRegex: '(a|b)+')
+test33 = (
+	assert:: rx string: 'abcde' prefixMatchesRegex: '(a|b)+')
+test34 = (
+assert:: (rx string: 'ab cd ab' copyWithRegex: '(a|b)+' matchesReplacedWith: 'foo') = 'foo cd foo'
+)
+test35 = (
+	assert:: (rx string: 'ab cd ab' copyWithRegex: '(a|b)+' matchesTranslatedUsing: [:e|e asUppercase]) = 'AB cd AB'
+)
+test36 = (
+	| matcher result |
+	matcher:: rx RxMatcher forString: '(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)[ ]+(:isDigit::isDigit:?)[ ]*,[ ]*(19|20)(:isDigit::isDigit:)'.
+	result:: (matcher matches: 'Aug 6, 1996')
+		ifTrue: 
+			[Array 
+				with: (matcher subexpression: 5)
+				with: (matcher subexpression: 2)
+				with: (matcher subexpression: 3)]
+		ifFalse: ['no match'].
 
-(
-
-
-
-class RegexTestCase selector: s = TestCase selector: s (
-|
-|
-)
-
-(
-
-
-
-class NormalConfiguration = TestConfiguration (
-|
-	
-|
-)
-
-('as yet unclassified'
-
-configure: platform = (
-
-
-
-testModuleName ^ <Symbol> = (
-
-
-
-)'as yet unclassified'
-
-test1 = (
-
-
-
-test10 = (
-
-
-
-test11 = (
-
-
-
-test12 = (
-
-
-
-test13 = (
-
-
-
-test14 = (
-
-
-
-test15 = (
-
-
-
-test16 = (
-
-
-
-test17 = (
-
-
-
-test18 = (
-
-
-
-test19 = (
-
-
-
-test2 = (
-
-
-
-test20 = (
-
-
-
-test21 = (
-
-
-
-test22 = (
-
-
-
-test23 = (
-
-
-
-test24 = (
-
-
-
-test25 = (
-
-
-
-test26 = (
-
-
-
-test27 = (
-
-
-
-test28 = (
-
-
-
-test29 = (
-
-
-
-test3 = (
-
-
-
-test30 = (
-
-
-
-test31 = (
-
-
-
-test32 = (
-
-
-
-test33 = (
-
-
-
-test34 = (
-
-
-
-test35 = (
-
-
-
-test36 = (
-
-
-
-test37 = (
-
-
-
-test38 = (
-
-
-
-test39 = (
-
-
-
-test4 = (
-
-
-
-test5 = (
-
-
-
-test6 = (
-
-
-
-test7 = (
-
-
-
-test8 = (
-
-
-
-test9 = (
-
-
-
-))
+	self assert: result = {'96'. 'Aug'. '6'}.
+)
+test37 = (
+	| matcher |
+	matcher:: rx RxMatcher forString: '\<\d\D+'.
+	assert:: (matcher copy: '9aaa1bbb 8ccc' replacingMatchesWith: 'foo') 
+				= 'foo1bbb foo'
+)
+test38 = (
+	| matcher |
+	matcher:: rx RxMatcher forString: '\w+'.
+	assert:: (matcher copy: 'now is  the   time    '
+				translatingMatchesUsing: [:s | s reverse]) = 'won si  eht   emit    '
+)
+test39 = (
+	| matcher |
+	matcher:: rx RxMatcher forString: '\w+'.
+	assert:: (matcher matchesIn: 'now is the time') asArray 
+				= {'now'. 'is'. 'the'. 'time'}
+)
+test4 = (
+	assert:: rx string: 'ab' matchesRegex: 'a*b')
+test5 = (
+assert:: rx string: 'aaaaab' matchesRegex: 'a*b')
+test6 = (
+	assert:: rx string: 'b' matchesRegex: 'a*b')
+test7 = (
+	deny:: rx string: 'aac' matchesRegex: 'a*b')
+test8 = (
+	assert:: rx string: 'abbb' matchesRegex: 'ab*')
+test9 = (
+	deny:: rx string: 'abab' matchesRegex: 'ab*'
+)) : ('as yet unclassified'
+TEST_CONTEXT = ()))

RegexTestingConfiguration.ns3

+Newspeak3
+'Regex'
+class RegexTestingConfiguration packageTestsUsing: ideNamespace = (
+"Describe the class in this comment."|
+	RegexMatcher = ideNamespace RegexMatcher.
+	RegexTesting = ideNamespace RegexTesting.
+|)
+('as yet unclassified'
+testModulesUsingPlatform: platform <Platform> minitest: minitest <Minitest> ^<{RegexTesting}> = (
+	| regex = RegexMatcher usingPlatform: platform. |
+	^{RegexTesting usingRegex: regex minitest: minitest}.
+))