1+ import { describe , it , expect } from 'vitest' ;
12import { Scope } from '../src' ;
23
34describe ( 'scopes' , ( ) => {
@@ -24,4 +25,55 @@ describe('scopes', () => {
2425 expect ( outer . getValue ( 'foo' ) ) . toEqual ( 'bar' ) ;
2526 }
2627 } ) ;
28+ it ( 'should not return value for non-existent identifiers' , ( ) => {
29+ const scope = Scope ( ) ;
30+ {
31+ const scoped = scope . withScope ( { foo : 'bar' } ) ;
32+ expect ( scoped . getValue ( 'baz' ) ) . toEqual ( null ) ;
33+ expect ( scoped . getValue ( 'foo' ) ) . toEqual ( 'bar' ) ;
34+ }
35+ } ) ;
36+ it ( 'should return null for identifiers even in nested scopes if absent' , ( ) => {
37+ const scope = Scope ( ) ;
38+ {
39+ const outer = scope . withScope ( { foo : 'bar' } ) ;
40+ {
41+ const inner = outer . withScope ( { bar : 'baz' } ) ;
42+ expect ( inner . getValue ( 'qux' ) ) . toEqual ( null ) ;
43+ }
44+ expect ( outer . getValue ( 'qux' ) ) . toEqual ( null ) ;
45+ }
46+ } ) ;
47+ it ( 'should handle values in nested scopes differently from outer scopes' , ( ) => {
48+ const scope = Scope ( ) ;
49+ {
50+ const outer = scope . withScope ( { foo : 'bar' } ) ;
51+ {
52+ const inner = outer . withScope ( { bar : 'baz' } ) ;
53+ expect ( inner . getValue ( 'foo' ) ) . toEqual ( 'bar' ) ;
54+ expect ( inner . getValue ( 'bar' ) ) . toEqual ( 'baz' ) ;
55+ }
56+ }
57+ } ) ;
58+ it ( 'should not fall through to outer scope when key is in current scope with null/undefined' , ( ) => {
59+ const scope = Scope ( ) ;
60+ {
61+ const outer = scope . withScope ( { foo : 'bar' } ) ;
62+ {
63+ const inner = outer . withScope ( { foo : null } ) ;
64+ expect ( inner . getValue ( 'foo' ) ) . toEqual ( null ) ;
65+ }
66+ }
67+ } ) ;
68+ it ( 'should properly differentiate between keys absent entirely and those in outer scopes' , ( ) => {
69+ const scope = Scope ( ) ;
70+ {
71+ const outer = scope . withScope ( { foo : 'bar' } ) ;
72+ {
73+ const inner = outer . withScope ( { } ) ;
74+ expect ( inner . getValue ( 'foo' ) ) . toEqual ( 'bar' ) ;
75+ expect ( inner . getValue ( 'baz' ) ) . toEqual ( null ) ;
76+ }
77+ }
78+ } ) ;
2779} ) ;
0 commit comments