-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6b85076
commit dd957ae
Showing
2 changed files
with
35 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
tests/baseline_compat/hyperon-mettalog_sanity/coerce_tests.metta
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
;; coerce is no-op when type already matches | ||
|
||
!(assertEqualToResult (coerce Bool True) (True)) | ||
!(assertEqualToResult (coerce Bool False) (False)) | ||
!(assertEqualToResult (coerce Number 1) (1)) | ||
!(assertEqualToResult (coerce Number 1.5) (1.5)) | ||
!(assertEqualToResult (coerce String "string") ("string")) | ||
|
||
;; coerce Bool makes 0 and () False, everything else True | ||
|
||
!(assertEqualToResult (coerce Bool 0) (False)) | ||
!(assertEqualToResult (coerce Bool ()) (False)) | ||
!(assertEqualToResult (coerce Bool 1) (True)) | ||
!(assertEqualToResult (coerce Bool "string") (True)) | ||
!(assertEqualToResult (coerce Bool (1 2 3)) (True)) | ||
|
||
;; coerce Number handles bools, number strings | ||
|
||
!(assertEqualToResult (coerce Number False) (0)) | ||
!(assertEqualToResult (coerce Number True) (1)) | ||
!(assertEqualToResult (coerce Number "1") (1)) | ||
!(assertEqualToResult (coerce Number "1.5") (1.5)) | ||
!(assertEqualToResult (coerce Number "2147483647") (2147483647)) | ||
!(assertEqualToResult (coerce Number "2147483648") (2147483648)) | ||
!(assertEqualToResult (coerce Number "not a number string") ()) | ||
|
||
;; coerce String acts as if printing object | ||
|
||
!(assertEqualToResult (coerce String False) ("'False'")) | ||
!(assertEqualToResult (coerce String True) ("'True'")) | ||
!(assertEqualToResult (coerce String 1) ("1")) | ||
!(assertEqualToResult (coerce String 1.5) ("1.5")) | ||
!(assertEqualToResult (coerce String ()) ("[]")) | ||
!(assertEqualToResult (coerce String (1 2 3)) ("[1,2,3]")) |