Commits

Felix Geller  committed 928d86a

More tests to ensure lexical scoping of pattern variables.

  • Participants
  • Parent commits d7a88ec

Comments (0)

Files changed (1)

File PatternMatchingTests.ns3

 class PatternMatchingTests usingPlatform: platform testFramework: minitest = NewspeakObject (
 "Tests for Newspeaks pattern matching facilities."|
 	private TestContext = minitest TestContext.
+	private MessageNotUnderstood = platform MessageNotUnderstood.
 |)
 (
 class LexicalScopingTests = TestContext (
 match: p = (
 	^ p testSubject: self
 ))'as yet unclassified'
+pattern ^ <Pattern> = (
+	^ <testSubject: ?x>.
+)
 setPattern = (
-	patternSlot: <testSubject: ?x>.
+	patternSlot: pattern.
+)
+testLexicalScopeAccessClosureThroughMethod = (
+|	a |
+	setPattern.
+	[ a:: TestSubject new 
+			case: <testSubject: ?x> => variableXAccessor 
+			otherwise: [ false ]]
+	on: MessageNotUnderstood do: [ :mnu | a:: mnu ].
+	assert: a message selector = 'x'.
 )
 testLexicalScopeAccessPatternThroughGetter = (
 |	a |
 	setPattern.
-	a:: TestSubject new case: patternSlot => [ x ] otherwise: [ false ].
-	assert: a not.
+	[ a:: TestSubject new case: patternSlot => [ x ] otherwise: [ false ]]
+	on: MessageNotUnderstood do: [ :mnu | a:: mnu ].
+	assert: a message selector = 'x'.
+)
+testLexicalScopeAccessPatternThroughMethod = (
+|	a |
+	setPattern.
+	[ a:: TestSubject new case: pattern => [ x ] otherwise: [ false ]]
+	on: MessageNotUnderstood do: [ :mnu | a:: mnu ].
+	unsetPattern.
+	assert: a message selector = 'x'.
 )
 testTestSubject = (
 |	ts = TestSubject new. 
 	a |
 	a:: ts case: <testSubject: ?x> => [ x ] otherwise: [ false ].
 	assert: a == ts.
+)
+unsetPattern = (
+	patternSlot: nil.
+)
+variableXAccessor ^ <[]> = (
+	^ [ x ]
 )) : ('as yet unclassified'
 TEST_CONTEXT = (