Skip to content

Commit

Permalink
add unit tests #280
Browse files Browse the repository at this point in the history
  • Loading branch information
jcubic committed Mar 25, 2024
1 parent 0e18b44 commit 0db3abb
Show file tree
Hide file tree
Showing 9 changed files with 648 additions and 27 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
[![npm](https://img.shields.io/badge/npm-1.0.0%E2%80%93beta.18.1-blue.svg)](https://www.npmjs.com/package/@jcubic/lips)
![1.0.0 Complete](https://img.shields.io/github/milestones/progress-percent/jcubic/lips/1?label=1.0.0%20Complete)
[![Build and test](https://github.com/jcubic/lips/actions/workflows/build.yaml/badge.svg?branch=devel&event=push)](https://github.com/jcubic/lips/actions/workflows/build.yaml)
[![Coverage Status](https://coveralls.io/repos/github/jcubic/lips/badge.svg?branch=devel&fb420559c6037d7ad3fafa6354d1553f)](https://coveralls.io/github/jcubic/lips?branch=devel)
[![Coverage Status](https://coveralls.io/repos/github/jcubic/lips/badge.svg?branch=devel&841e19e1aca88cafb5aedb4f3aee9ca6)](https://coveralls.io/github/jcubic/lips?branch=devel)
[![Join Gitter Chat](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/jcubic/lips)
![NPM Download Count](https://img.shields.io/npm/dm/@jcubic/lips)
![JSDelivr Download count](https://img.shields.io/jsdelivr/npm/hm/@jcubic/lips)
Expand Down
10 changes: 5 additions & 5 deletions dist/lips.cjs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions dist/lips.esm.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions dist/lips.esm.min.js

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions dist/lips.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions dist/lips.min.js

Large diffs are not rendered by default.

24 changes: 17 additions & 7 deletions tests/parser.scm
Original file line number Diff line number Diff line change
Expand Up @@ -223,45 +223,55 @@
))
(t.is (x.valueOf) "\n"))))


(test "parser: should throw error on quote without expression"
(lambda (t)
(let ((specs '("(list ')" "(list '')")))
(for-each (lambda (code)
(t.is (to.throw (lips.parse code)) #t))
specs))))

(test "parser: should throw an error on invalid dot sequennce #245"
(lambda (t)
(t.is (to.throw (lips.parse "(1 . 2 3)")) #t)))

(test "tokenizer: should create tokens for simple list"
(test "lexer: should create tokens for simple list"
(lambda (t)
(t.is (lips.tokenize "(foo bar baz)")
#("(" "foo" "bar" "baz" ")"))))

(test "tokenizer: should create tokens for numbers string and regexes"
(test "lexer: should create tokens for numbers string and regexes"
(lambda (t)
(t.is (lips.tokenize "(foo #/( \\/)/g \"bar baz\" 10 1.1 10e2
10+10i +inf.0+inf.0i +nan.0+nan.0i 1/2+1/2i)")
#("(" "foo" "#/( \\/)/g" "\"bar baz\"" "10" "1.1" "10e2"
"10+10i" "+inf.0+inf.0i" "+nan.0+nan.0i" "1/2+1/2i" ")"))))

(test "tokenizer: should create token for alist"
(test "lexer: should create token for alist"
(lambda (t)
(t.is (lips.tokenize "((foo . 10) (bar . 20) (baz . 30))")
#("(" "(" "foo" "." "10" ")" "(" "bar" "." "20" ")" "("
"baz" "." "30" ")" ")"))))

(test "tokenizer: should ignore comments"
(test "lexer: should ignore comments"
(lambda (t)
(let ((code "(foo bar baz); (baz quux)"))
(t.is (lips.tokenize code)
#("(" "foo" "bar" "baz" ")")))))

(test "tokenizer: should handle semicolon in regexes and strings"
(test "lexer: should handle semicolon in regexes and strings"
(lambda (t)
(let ((code "(\";()\" #/;;;/g baz); (baz quux)"))
(t.is (lips.tokenize code)
#("(" "\";()\"" "#/;;;/g" "baz" ")")))))

(test "tokenizer: with meta data"
(test "lexer: with meta data"
(lambda (t)
(let* ((fs (require "fs"))
(code (--> (fs.promises.readFile "./tests/stubs/macro.txt")
(toString))))
(t.snapshot (lips.tokenize code true)))))

(test "lexer: should throw error on unterminated string"
(lambda (t)
(let ((code "\"foo"))
(t.is (to.throw (lips.tokenize code)) #t))))
Loading

0 comments on commit 0db3abb

Please sign in to comment.