Skip to content

Commit 8479ae3

Browse files
Used new features
Split everything.fbl to 2 modules: core and tools Changed the testing framework to use `puts`
1 parent 61543db commit 8479ae3

File tree

4 files changed

+34
-27
lines changed

4 files changed

+34
-27
lines changed

language/core.fbl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
: ( set "void" [ --- ] void )
2+
: ( set "run" [ function ] function void )
3+
4+
5+
: ( set "__equals" equals )
6+
: ( set "equals" [ left ] [ right ] __if (__equals left right) true false )
7+
8+
9+
: ( set "true" [ first ] [ second ] first )
10+
: ( set "false" [ first ] [ second ] second )
11+
: ( set "__if" if )
12+
: ( set "if" [ condition ] [ on_true ] [ on_false ] condition on_true on_false )

language/program.fbl

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
: include "everything.fbl"
1+
: include "core.fbl"
2+
: include "tools.fbl"
23
: include "testing.fbl"
34

45

@@ -25,13 +26,13 @@
2526
: (set "main" [ args ]
2627
: test "functions" ([ --- ]
2728
: describe "context_parent" ([ --- ]
28-
: assert_equals (42) (context_parent 42) "should return the input"
29-
: assert_equals ("foo") (context_parent "foo") "should return the input"
30-
: assert_equals (test) (context_parent test) "should return the input"
29+
: assert_equals (42) (context_parent 42) "return integer (42)"
30+
: assert_equals ("foo") (context_parent "foo") "return string (foo)"
31+
: assert_equals (test) (context_parent test) "return function(test)"
3132
:
32-
: assert_equals (void) (context_parent_global 42) "should NOT return the input"
33-
: assert_equals (void) (context_parent_global "foo") "should NOT return the input"
34-
: assert_equals (void) (context_parent_global test) "should NOT return the input"
33+
: assert_equals (void) (context_parent_global 42) "return void (ignore integer (42))"
34+
: assert_equals (void) (context_parent_global "foo") "return void (ignore string (foo))"
35+
: assert_equals (void) (context_parent_global test) "return void (ignore function(test))"
3536
)
3637
: describe "factorial" ([ --- ]
3738
: assert_equals (1) (factorial 0) "0! == 1"
@@ -51,12 +52,11 @@
5152
: assert_equals 3 (% 17 7) "17 % 7 == 3"
5253
)
5354
: describe "convertion" ([ --- ]
54-
: assert_equals 10 (int "10") "should convert string to integer"
55-
: assert_equals 10 (int "10.5") "should convert string with trailing symbols to integer"
56-
: assert_equals 10 (int 10.5) "should convert decimal numbers to integers"
57-
` TODO: Add '.' as a separator
58-
` : assert_equals 10.5 (number "10.5") "should convert string to decimal number"
59-
: assert_equals "1" (string 1) "should convert numbers to string"
55+
: assert_equals 10 (int "10") "convert string to integer"
56+
: assert_equals 10 (int "10.5") "convert string with trailing symbols to integer"
57+
: assert_equals 10 (int 10.5) "convert decimal numbers to integers"
58+
: assert_equals 10.5 (number "10.5") "convert string to decimal number"
59+
: assert_equals "1" (string 1) "convert numbers to string"
6060
)
6161
)
6262
: test "std" ([ --- ]

language/testing.fbl

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
: include "everything.fbl"
1+
: include "core.fbl"
2+
: include "tools.fbl"
23

34

45
` Declaring counters in global scope
@@ -9,16 +10,16 @@
910

1011
` Tests wrappers
1112
: ( set "test" [ title ] [ code ]
12-
: print (+ (+ "\n===--- " title) " ---===")
13+
: puts "\n===--- " title " ---===\n"
1314

1415
: set "_$tests_total" 0
1516
: set "_$tests_passed" 0
1617
: run code
17-
: print (+ (+ (+ "\nTests passed: " _$tests_passed) " / ") _$tests_total)
18+
: puts "\nTests passed: " _$tests_passed " / " _$tests_total "\n"
1819
)
1920

2021
: ( set "describe" [ title ] [ code ]
21-
: print (+ "Testing #" title)
22+
: puts "\nTesting #" title "\n"
2223
: run code
2324
)
2425

@@ -27,6 +28,6 @@
2728
: ( set "assert_equals" [ expected ] [ actual ] [ message ] run (
2829
: set "_$tests_total" (+ _$tests_total 1)
2930
: if (not (equals expected actual))
30-
([ --- ] print (+ (+ (+ (+ (+ "FAILED...\n Expected " expected) " but got ") actual) "\n Message: ") message))
31-
([ --- ] print (+ " passed - " message) : set "_$tests_passed" (+ _$tests_passed 1))
31+
([ --- ] puts " FAILED...\n Expected " expected " but got " actual "\n Message: " message "\n")
32+
([ --- ] puts " passed - " message "\n" : set "_$tests_passed" (+ _$tests_passed 1))
3233
) )
Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
1-
: ( set "__equals" equals )
2-
: ( set "equals" [ left ] [ right ] __if (__equals left right) true false )
1+
: include "core.fbl"
32

4-
: ( set "true" [ first ] [ second ] first )
5-
: ( set "false" [ first ] [ second ] second )
6-
: ( set "__if" if )
7-
: ( set "if" [ condition ] [ on_true ] [ on_false ] condition on_true on_false )
83

4+
` Convertion tools
95
: ( set "bool" [ value ] __if value true false )
106
: ( set "bti" [ value ] value 1 0 )
117

@@ -19,8 +15,6 @@
1915

2016

2117
` Utility functions
22-
: ( set "void" [ --- ] void )
23-
: ( set "run" [ function ] function void )
2418
: ( set "id" [ value ] value )
2519
: ( set "power" [ _power ] [ function ] [ value ] run (
2620
__if _power

0 commit comments

Comments
 (0)