@@ -4,114 +4,114 @@ import { describe, it } from "@effectionx/bdd";
44import { useEvalScope , unbox , box } from "./mod.ts" ;
55
66describe ( "box" , ( ) => {
7- it ( "returns Ok for successful operations" , function * ( ) {
8- const result = yield * box ( function * ( ) {
9- return 42 ;
10- } ) ;
11-
12- expect ( result . ok ) . toBe ( true ) ;
13- if ( result . ok ) {
14- expect ( result . value ) . toBe ( 42 ) ;
15- }
16- } ) ;
17-
18- it ( "returns Err for failed operations" , function * ( ) {
19- const result = yield * box ( function * ( ) {
20- throw new Error ( "test error" ) ;
21- } ) ;
22-
23- expect ( result . ok ) . toBe ( false ) ;
24- if ( ! result . ok ) {
25- expect ( result . error . message ) . toBe ( "test error" ) ;
26- }
27- } ) ;
7+ it ( "returns Ok for successful operations" , function * ( ) {
8+ const result = yield * box ( function * ( ) {
9+ return 42 ;
10+ } ) ;
11+
12+ expect ( result . ok ) . toBe ( true ) ;
13+ if ( result . ok ) {
14+ expect ( result . value ) . toBe ( 42 ) ;
15+ }
16+ } ) ;
17+
18+ it ( "returns Err for failed operations" , function * ( ) {
19+ const result = yield * box ( function * ( ) {
20+ throw new Error ( "test error" ) ;
21+ } ) ;
22+
23+ expect ( result . ok ) . toBe ( false ) ;
24+ if ( ! result . ok ) {
25+ expect ( result . error . message ) . toBe ( "test error" ) ;
26+ }
27+ } ) ;
2828} ) ;
2929
3030describe ( "unbox" , ( ) => {
31- it ( "extracts value from Ok result" , function * ( ) {
32- const result = yield * box ( function * ( ) {
33- return "hello" ;
34- } ) ;
31+ it ( "extracts value from Ok result" , function * ( ) {
32+ const result = yield * box ( function * ( ) {
33+ return "hello" ;
34+ } ) ;
3535
36- expect ( unbox ( result ) ) . toBe ( "hello" ) ;
37- } ) ;
36+ expect ( unbox ( result ) ) . toBe ( "hello" ) ;
37+ } ) ;
3838
39- it ( "throws error from Err result" , function * ( ) {
40- const result = yield * box ( function * ( ) {
41- throw new Error ( "should throw" ) ;
42- } ) ;
39+ it ( "throws error from Err result" , function * ( ) {
40+ const result = yield * box ( function * ( ) {
41+ throw new Error ( "should throw" ) ;
42+ } ) ;
4343
44- expect ( ( ) => unbox ( result ) ) . toThrow ( "should throw" ) ;
45- } ) ;
44+ expect ( ( ) => unbox ( result ) ) . toThrow ( "should throw" ) ;
45+ } ) ;
4646} ) ;
4747
4848describe ( "useEvalScope" , ( ) => {
49- it ( "can evaluate operations in a separate scope" , function * ( ) {
50- const context = createContext < string > ( "test-context" ) ;
49+ it ( "can evaluate operations in a separate scope" , function * ( ) {
50+ const context = createContext < string > ( "test-context" ) ;
5151
52- const evalScope = yield * useEvalScope ( ) ;
52+ const evalScope = yield * useEvalScope ( ) ;
5353
54- // Context not set yet
55- expect ( evalScope . scope . get ( context ) ) . toBeUndefined ( ) ;
54+ // Context not set yet
55+ expect ( evalScope . scope . get ( context ) ) . toBeUndefined ( ) ;
5656
57- // Evaluate an operation that sets context
58- const result = yield * evalScope . eval ( function * ( ) {
59- yield * context . set ( "Hello World!" ) ;
60- return "done" ;
61- } ) ;
57+ // Evaluate an operation that sets context
58+ const result = yield * evalScope . eval ( function * ( ) {
59+ yield * context . set ( "Hello World!" ) ;
60+ return "done" ;
61+ } ) ;
6262
63- // Context is now visible via scope
64- expect ( evalScope . scope . get ( context ) ) . toBe ( "Hello World!" ) ;
65- expect ( unbox ( result ) ) . toBe ( "done" ) ;
66- } ) ;
63+ // Context is now visible via scope
64+ expect ( evalScope . scope . get ( context ) ) . toBe ( "Hello World!" ) ;
65+ expect ( unbox ( result ) ) . toBe ( "done" ) ;
66+ } ) ;
6767
68- it ( "captures errors as Result.Err" , function * ( ) {
69- const evalScope = yield * useEvalScope ( ) ;
68+ it ( "captures errors as Result.Err" , function * ( ) {
69+ const evalScope = yield * useEvalScope ( ) ;
7070
71- const result = yield * evalScope . eval ( function * ( ) {
72- throw new Error ( "boom" ) ;
73- } ) ;
71+ const result = yield * evalScope . eval ( function * ( ) {
72+ throw new Error ( "boom" ) ;
73+ } ) ;
7474
75- expect ( result . ok ) . toBe ( false ) ;
76- if ( ! result . ok ) {
77- expect ( result . error . message ) . toBe ( "boom" ) ;
78- }
79- } ) ;
75+ expect ( result . ok ) . toBe ( false ) ;
76+ if ( ! result . ok ) {
77+ expect ( result . error . message ) . toBe ( "boom" ) ;
78+ }
79+ } ) ;
8080
81- it ( "can evaluate multiple operations in sequence" , function * ( ) {
82- const counter = createContext < number > ( "counter" ) ;
81+ it ( "can evaluate multiple operations in sequence" , function * ( ) {
82+ const counter = createContext < number > ( "counter" ) ;
8383
84- const evalScope = yield * useEvalScope ( ) ;
84+ const evalScope = yield * useEvalScope ( ) ;
8585
86- yield * evalScope . eval ( function * ( ) {
87- yield * counter . set ( 1 ) ;
88- } ) ;
86+ yield * evalScope . eval ( function * ( ) {
87+ yield * counter . set ( 1 ) ;
88+ } ) ;
8989
90- yield * evalScope . eval ( function * ( ) {
91- const current = evalScope . scope . get ( counter ) ?? 0 ;
92- yield * counter . set ( current + 1 ) ;
93- } ) ;
90+ yield * evalScope . eval ( function * ( ) {
91+ const current = evalScope . scope . get ( counter ) ?? 0 ;
92+ yield * counter . set ( current + 1 ) ;
93+ } ) ;
9494
95- expect ( evalScope . scope . get ( counter ) ) . toBe ( 2 ) ;
96- } ) ;
95+ expect ( evalScope . scope . get ( counter ) ) . toBe ( 2 ) ;
96+ } ) ;
9797
98- it ( "child scope can see parent context but setting creates own value" , function * ( ) {
99- const context = createContext < string > ( "inherited" ) ;
98+ it ( "child scope can see parent context but setting creates own value" , function * ( ) {
99+ const context = createContext < string > ( "inherited" ) ;
100100
101- // Set context in parent scope
102- yield * context . set ( "parent value" ) ;
101+ // Set context in parent scope
102+ yield * context . set ( "parent value" ) ;
103103
104- const evalScope = yield * useEvalScope ( ) ;
104+ const evalScope = yield * useEvalScope ( ) ;
105105
106- // Child scope CAN see parent's context (Effection context inheritance)
107- expect ( evalScope . scope . get ( context ) ) . toBe ( "parent value" ) ;
106+ // Child scope CAN see parent's context (Effection context inheritance)
107+ expect ( evalScope . scope . get ( context ) ) . toBe ( "parent value" ) ;
108108
109- // Set in child scope - this creates a new value in the child
110- yield * evalScope . eval ( function * ( ) {
111- yield * context . set ( "child value" ) ;
112- } ) ;
109+ // Set in child scope - this creates a new value in the child
110+ yield * evalScope . eval ( function * ( ) {
111+ yield * context . set ( "child value" ) ;
112+ } ) ;
113113
114- // Child now has its own value
115- expect ( evalScope . scope . get ( context ) ) . toBe ( "child value" ) ;
116- } ) ;
114+ // Child now has its own value
115+ expect ( evalScope . scope . get ( context ) ) . toBe ( "child value" ) ;
116+ } ) ;
117117} ) ;
0 commit comments