Commits

Felix Geller committed 0fc3a28

Add test to ensure lexical scoping when using pattern variables.

  • Participants
  • Parent commits 00f4f48

Comments (0)

Files changed (1)

PatternMatchingTests.ns3

 	private TestContext = minitest TestContext.
 |)
 (
+class LexicalScopingTests = TestContext (
+"If a pattern defines a pattern variable (e.g., ?x) and one uses the application combinator on such a pattern, then the pattern variable should only be accessible in closures (that are parameters to the application combinator) that are defined in the same context as the pattern that defines the pattern variable.
+
+This class contains tests that ensure that this is true."|
+	patternSlot
+|)
+(
+class TestSubject = (|
+|)
+('as yet unclassified'
+match: p = (
+	^ p testSubject: self
+))'as yet unclassified'
+setPattern = (
+	patternSlot: <testSubject: ?x>.
+)
+testLexicalScopeAccessPatternThroughGetter = (
+|	a |
+	setPattern.
+	a:: TestSubject new case: patternSlot => [ x ] otherwise: [ false ].
+	assert: a not.
+)
+testTestSubject = (
+|	ts = TestSubject new. 
+	a |
+	a:: ts case: <testSubject: ?x> => [ x ] otherwise: [ false ].
+	assert: a == ts.
+)) : ('as yet unclassified'
+TEST_CONTEXT = (
+	
+))
 class SimplificationTests = TestContext (|
 |)
 (