-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.js
More file actions
111 lines (102 loc) · 2.5 KB
/
test.js
File metadata and controls
111 lines (102 loc) · 2.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
import * as mod from './mod.js'
import {jevkoFromString} from 'https://cdn.jsdelivr.net/gh/jevko/jevko.js@v0.1.5/mod.js'
import { assertEquals } from "https://deno.land/std@0.170.0/testing/asserts.ts";
Deno.test('basic', () => {
const jevko = jevkoFromString(`
list [
[a]
[b]
[hello]
[400.9]
[
[x][y][z]
]
]
person [
first name [John]
last name [Smith]
is alive [true]
age [27]
address [
street address [21 2nd Street]
city [New York]
state [NY]
postal code [10021-3100]
]
phone numbers [
[
type [home]
number [212 555-1234]
]
[
type [office]
number [646 555-4567]
]
]
children [seq]
spouse [nil]
]
`)
const parsePhoneNumber = (jevko) => {
let _ = mod.toMap(jevko)
return {
type: mod.toString(_.type),
number: mod.toString(_.number),
}
}
const parseSpouse = (jevko) => {
if (jevko.subjevkos.length === 0) {
if (jevko.suffix === 'nil') return null
}
throw Error('not implemented')
}
const parsePerson = (jevko) => {
let _ = mod.toMap(jevko)
let address
{
let a = mod.toMap(_.address)
address = {
streetAddress: mod.toString(a['street address']),
city: mod.toString(a.city),
state: mod.toString(a.state),
postalCode: mod.toString(a['postal code']),
}
}
return {
firstName: mod.toString(_['first name']),
lastName: mod.toString(_['last name']),
isAlive: mod.toBoolean(_['is alive']),
age: mod.toNumber(_.age),
address,
phoneNumbers: mod.toList(_['phone numbers']).map(_ => parsePhoneNumber(_)),
children: mod.toList(_.children),
spouse: parseSpouse(_.spouse),
}
}
let _ = mod.toMap(jevko)
assertEquals(parsePerson(_.person), {
firstName: "John",
lastName: "Smith",
isAlive: true,
age: 27,
address: {
streetAddress: "21 2nd Street",
city: "New York",
state: "NY",
postalCode: "10021-3100"
},
phoneNumbers: [
{ type: "home", number: "212 555-1234" },
{ type: "office", number: "646 555-4567" }
],
children: [],
spouse: null
})
_ = mod.toList(_.list)
const str = mod.toString(_[2])
const num = mod.toNumber(_[3])
const lis = mod.toList(_[4]).map(_ => mod.toString(_))
assertEquals(str, "hello")
assertEquals(num, 400.9)
assertEquals(lis, ["x", "y", "z"])
})