Skip to content

Commit

Permalink
Fix issue with multiple complex structures in union
Browse files Browse the repository at this point in the history
Fixes #11
Fixes #10
  • Loading branch information
gkz committed Apr 3, 2020
1 parent b518bbc commit 6a2c33c
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 6 deletions.
10 changes: 6 additions & 4 deletions lib/parse-type.js

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

4 changes: 2 additions & 2 deletions src/parse-type.ls
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,9 @@ function consume-types tokens
* type: 'Null'
types-so-far = {+Undefined, +Null}
for ever
{type}:type-obj = consume-type tokens
{type, structure}:type-obj = consume-type tokens
types.push type-obj unless types-so-far[type]
types-so-far[type] = true
types-so-far[type] = true unless structure?
break unless maybe-consume-op tokens, '|'
types

Expand Down
4 changes: 4 additions & 0 deletions test/check.ls
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ suite 'check' ->
test 'multiple' ->
assert c 'Number | String', 'hi'
assert not c 'Date | Number', 'hi'
assert c 'String | [String] | [Object]', [{}]

suite 'Array' ->
test 'bare' ->
Expand Down Expand Up @@ -236,6 +237,9 @@ suite 'check' ->
assert c type, {a: ['hi', [1, 2, 3], {x: {a: 42}, y: [1, 'bye']}], b: new Error 'message'}
assert c type, {a: ['moo', [3], {x: {}, y: [], z: 999}], b: new Error '23'}

test 'nexted with union' ->
assert c '[[Number] | [String]]', [[1, 2], ['foo', 'bar'], [3]]

suite 'errors' ->
test 'no type defined' ->
throws (-> parsed-type-check [{}], true), /No type defined\. Input: true/
Expand Down
11 changes: 11 additions & 0 deletions test/parse-type.ls
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,17 @@ suite 'parse type' ->
]
]

test 'nested with multiple' ->
deep-equal (p '[[Number] | [String]]'), [
structure: 'array'
of: [
* structure: 'array'
of: [type: 'Number']
* structure: 'array'
of: [type: 'String']
]
]

suite 'array structure with type' ->
test 'simple' ->
deep-equal (p 'Int16Array[Int]'), [
Expand Down

0 comments on commit 6a2c33c

Please sign in to comment.