Best JavaScript code snippet using storybook-root
main.test.ts
Source:main.test.ts
1import { toChar, isAtom, isList, first, rest } from './parser';2import { ParseAtom, Atom, List, ParseList } from "./parser";3import { Evaluate, Execute } from "./evaluator";4describe.skip('Parse', () => {5 test('expect return: array of chars', () => {6 const input = toChar('abc')7 const expected = ['a', 'b', 'c']8 expect(input).toEqual(expected)9 })10 test('should return a number of Atom, given a string containing a number', () => {11 const input = ParseAtom('1')12 const expected = <Atom<number>> {value: 1}13 expect(expected.value).toBe(input.value)14 })15})16describe.skip('ParseAtom', () => {17 test('should return a symbol of Atom, given a string containing a name', () => {18 const input = ParseAtom('a')19 const expected = <Atom<string>> {value: 'a'}20 21 expect(expected.value).toBe(input.value)22 })23 24 test('throw error if the given string is invalid', () => {25 const input = () => {ParseAtom('')}26 expect(input).toThrowError(Error('invalid symbol'))27 })28})29describe.skip('ParseList', () => {30 test('throw error if the given string is invalid', () => {31 const input = () => {ParseList('')}32 expect(input).toThrowError(Error('Invalid expression'))33 })34 35 test('check open delimeter ( is exist', () => {36 const input = () => {ParseList("123")}37 expect(input).toThrowError("ListOpenDelimeter ( is not found")38 })39 40 test('return () for empty List', () => {41 const input = ParseList('()')42 const expected = <List> {items: []}43 expect(input.items.length).toBe(expected.items.length)44 })45 46 test('return a List with one element', () => {47 const input = ParseList('(1)')48 const expected = <List> { 49 items: [<Atom<number>> {value: 1}]50 }51 expect(input.items.length).toBe(expected.items.length)52 expect((<Atom<number>>expected.items[0]).value === ((<Atom<number>>input.items[0]).value)).toBe(true)53 })54 55 test('return 2 elements List', () => {56 const input = ParseList('(1 a)')57 const expected = <List> {58 items: [ <Atom<number>> {value: 1}, <Atom<string>> {value: 'a'} ]59 }60 expect(input.items.length).toBe(expected.items.length)61 expect((<Atom<number>>expected.items[0]).value === (<Atom<number>>input.items[0]).value).toBe(true)62 expect((<Atom<string>>expected.items[1]).value === ((<Atom<string>>input.items[1]).value)).toBe(true)63 })64 65 test('return list that contain operator', () => {66 const input = ParseList('(() 1 a)')67 const expected = <List> {68 items: [ 69 <List> {items: []}, 70 <Atom<number>> {value: 1}, 71 <Atom<string>> {value: 'a'} 72 ]73 }74 expect(input).toBe(expected)75 })76 77 test('return List, given a string with symbol and numeric Atoms', () => {78 const input = ParseList('(add 1 2)')79 const expected = <List> {80 items: [ 81 <Atom<string>> {value: 'add'}, 82 <Atom<number>> {value: 1}, 83 <Atom<number>> {value: 2} 84 ]85 }86 expect(input).toBe(expected)87 })88 89 test('return List, given operator and numeric Atoms', () => {90 const input = ParseList('(+ 1 2)')91 const expected = <List> {92 items: [93 <Atom<string>> {value: '+'}, 94 <Atom<number>> {value: 1}, 95 <Atom<number>> {value: 2} 96 ]97 } 98 expect(input).toBe(expected)99 })100 101 test('return List, given a string of arithmetic expression', () => {102 const input = ParseList('(+ 1 2 (* 3 4))')103 const expected = <List> {104 items: [105 <Atom<string>> {value: '+'},106 <Atom<number>> {value: 1}, 107 <Atom<number>> {value: 2},108 <List> {109 items: [110 <Atom<string>> {value: '*'},111 <Atom<number>> {value: 3},112 <Atom<number>> {value: 4}113 ]114 }115 ]116 }117 expect(input).toBe(expected)118 })119 120 test('return List given a deep nested list and arithmetic operator', () => {121 const input = ParseList('(((+ 1 2)))')122 const expected = <List> {123 items: [124 <List> {125 items: [126 <List> {127 items: [128 <Atom<string>> {value: '+'},129 <Atom<number>> {value: 1},130 <Atom<number>> {value: 2}131 ]132 }133 ]134 }135 ]136 }137 expect(input.items.length).toBe(expected.items.length)138 139 const b = (<List>input.items[0]).items140 const c = (<List>expected.items[0]).items141 expect(b.length).toBe(c.length)142 //console.log(b, c)143 144 const d = (<List>b[0]).items 145 const e = (<List>c[0]).items146 //console.log(d, e)147 expect(d.length).toBe(e.length)148 })149 150})151describe.skip('Eval', () => {152// List -> Evaluator -> Atom153// Match first element with kown operators154// recursively evaluate he rest of the list 155// Apply operator to Atoms 156// Return the result 157 test('isAtom: return true. if input is Atom', () => {158 const input = isAtom(<Atom<number>> {value: 3})159 expect(input).toBe(true)160 })161 test('isAtom: return false. if input is List', () => {162 const input = isAtom(<List> { items: []})163 expect(input).toBe(false)164 })165 166 test('isList: return true. if input is List', () => {167 const input = isList(<List> {items: []})168 expect(input).toBe(true)169 })170 171 test('isList: return false. if input is Atom', () => {172 const input = isList(<Atom<number>> {value: 3})173 expect(input).toBe(false)174 })175})176describe.skip('check List', () => {177 test('return ist element of a List', () => {178 const input = first(<List> {179 items: [ <Atom<number>> {value: 3} ]180 })181 const expected = <Atom<number>> {value: 3}182 expect(input.value).toBe(expected.value)183 })184 test('throw Error if input list is empty', () => {185 const input = () => {186 first(<List> { items: []})187 }188 expect(input).toThrowError(Error('List is empty'))189 })190 test('return the rest of List', () => {191 const input = rest(<List> {192 items: [193 <Atom<number>> {value: 3}194 ]195 })196 const expected = <List> {items: []}197 expect(input.items.length).toBe(expected.items.length)198 })199})200describe.skip('Arithmetic Operation', () => {201 test('+ : calculate arithmetic expression correctly', () => {202 const s = ParseList('(+ 1 2)')203 const input = Evaluate(s)204 const expected = <Atom<number>> {value: 3}205 expect(input.value).toBe(expected.value)206 })207 test('+ : return false if input is invalid form', () => {208 const s = ParseList('(+)')209 const input = () => {Evaluate(s)}210 expect(input).toThrowError('Not enought argument to the operation')211 })212 test('- : calculate arithmetic expression correctly', () => {213 const s = ParseList('(- 1 2)')214 const input = Evaluate(s)215 const expected = <Atom<number>> {value: -1}216 expect(input.value).toBe(expected.value)217 })218 test('- : calculate arithmetic expression correctly', () => {219 const s = ParseList('(- -1 2)')220 const input = Evaluate(s)221 const expected = <Atom<number>> {value: -3}222 expect(input.value).toBe(expected.value)223 })224 test('- : return false if input is invalid form', () => {225 const s = ParseList('(-)')226 const input = () => {Evaluate(s)}227 expect(input).toThrowError('Not enought argument to the operation')228 })229 test('* : calculate arithmetic expression correctly', () => {230 const s = ParseList('(* 1 2)')231 const input = Evaluate(s)232 const expected = <Atom<number>> {value: 2}233 expect(input.value).toBe(expected.value)234 })235 test('* : return false if input is invalid form', () => {236 const s = ParseList('(*)')237 const input = () => {Evaluate(s)}238 expect(input).toThrowError('Not enought argument to the operation')239 })240 test('/ : calculate arithmetic expression correctly', () => {241 const s = ParseList('(/ 4 2)')242 const input = Evaluate(s)243 const expected = <Atom<number>> {value: 2}244 expect(input.value).toBe(expected.value)245 })246 test('/ : return false if input is invalid form', () => {247 const s = ParseList('(/)')248 const input = () => {Evaluate(s)}249 expect(input).toThrowError('Not enought argument to the operation')250 })251 test('% : calculate arithmetic expression correctly', () => {252 const s = ParseList('(% 13 5)')253 const input = Evaluate(s)254 const expected = <Atom<number>> {value: 3}255 expect(input.value).toBe(expected.value)256 })257 test('% : return false if input is invalid form', () => {258 const s = ParseList('(%)')259 const input = () => {Evaluate(s)}260 expect(input).toThrowError('Not enought argument to the operation')261 })262 test('calculate nested arithmetic expression correctly', () => {263 const s = ParseList('(+ 1 2 3)')264 const input = Evaluate(s)265 const expected = <Atom<number>> {value: 6}266 expect(input.value).toBe(expected.value)267 })268 test('calculate nested arithmetic expression correctly', () => {269 const s = ParseList('(+ 1 2 3)')270 const input = Evaluate(s)271 const expected = <Atom<number>> {value: 6}272 expect(input.value).toBe(expected.value)273 })274 test('calculate complex arithmetic expression correctly', () => {275 const s = ParseList('(+ 1 2 (* 3 (/ 8 2)) 10)')276 const input = Evaluate(s)277 const expected = <Atom<number>> {value: 25}278 expect(input.value).toBe(expected.value)279 })280})281describe.skip('Comparison Operator', () => {282 test('parse comparison: ==', () => {283 const t = ParseList('(==)')284 const input = () => {Evaluate(t)}285 expect(input).toThrowError(Error("Comparision operator == needs 2 arguments. got=0"))286 })287 test('parse comparison: ==', () => {288 const t = ParseList('(== 1)')289 const input = () => {Evaluate(t)}290 expect(input).toThrowError(Error("Comparision operator == needs 2 arguments. got=1"))291 })292 test('== : return true', () => {293 const t = ParseList('(== 1 1)')294 const input = Evaluate(t)295 expect(input.value).toBe(true)296 })297 test('== : return false', () => {298 const t = ParseList('(== 1 -1)')299 const input = Evaluate(t)300 expect(input.value).toBe(false)301 })302 test('!= : return true', () => {303 const t = ParseList('(!= 1 2)')304 const input = Evaluate(t)305 expect(input.value).toBe(true)306 })307 test('!= : return false', () => {308 const t = ParseList('(!= 1 1)')309 const input = Evaluate(t)310 expect(input.value).toBe(false)311 })312 test('> : return true', () => {313 const t = ParseList('(> 2 1)')314 const input = Evaluate(t)315 expect(input.value).toBe(true)316 })317 test('> : return false', () => {318 const t = ParseList('(> 1 1)')319 const input = Evaluate(t)320 expect(input.value).toBe(false)321 })322 test('< : return true', () => {323 const t = ParseList('(< 1 2)')324 const input = Evaluate(t)325 expect(input.value).toBe(true)326 })327 test('< : return false', () => {328 const t = ParseList('(< 1 1)')329 const input = Evaluate(t)330 expect(input.value).toBe(false)331 })332 test('>= : return true', () => {333 const t = ParseList('(>= 2 2)')334 const input = Evaluate(t)335 expect(input.value).toBe(true)336 })337 test('>= : return false', () => {338 const t = ParseList('(>= 0 1)')339 const input = Evaluate(t)340 expect(input.value).toBe(false)341 })342 test('<= : return true', () => {343 const t = ParseList('(>= 2 2)')344 const input = Evaluate(t)345 expect(input.value).toBe(true)346 })347 test('<= : return false', () => {348 const t = ParseList('(<= 0 -1)')349 const input = Evaluate(t)350 expect(input.value).toBe(false)351 })352 test('complex comparison. return true', () => {353 const t = ParseList('(== (== 1 1) (!= a b))')354 const input = Evaluate(t)355 expect(input.value).toBe(true)356 })357 test('complex comparison. return false', () => {358 const t = ParseList('(!= (== 1 1) (!= a b))')359 const input = Evaluate(t)360 expect(input.value).toBe(false)361 })362})363describe.skip('Logical Ops', () => {364 test('throw error for lack of arguments. given only op', () => {365 const t = ParseList('(&&)')366 const input = () => { Evaluate(t) }367 expect(input).toThrowError(Error('Logical operator && needs 2 arguments. got=0'))368 })369 test('throw error for lack of arguments. given 1 op, 1 arg', () => {370 const t = ParseList('(&& true)')371 const input = () => { Evaluate(t) }372 expect(input).toThrowError(Error('Logical operator && needs 2 arguments. got=1'))373 })374 test('throw error for lack of arguments. given only op', () => {375 const t = ParseList('(||)')376 const input = () => { Evaluate(t) }377 expect(input).toThrowError(Error('Logical operator || needs 2 arguments. got=0'))378 })379 test('throw error for lack of arguments. given 1 op, 1 arg', () => {380 const t = ParseList('(|| true)')381 const input = () => { Evaluate(t) }382 expect(input).toThrowError(Error('Logical operator || needs 2 arguments. got=1'))383 })384 test('&&. return true', () => {385 const t = ParseList('(&& true true)')386 const input = Evaluate(t)387 expect(input.value).toBe(true)388 })389 // ------------------390 test('&&. return false', () => {391 const t = ParseList('(&& true false)')392 const input = Evaluate(t)393 expect(input.value).toBe(false)394 })395 test('&&. return false', () => {396 const t = ParseList('(&& false true)')397 const input = Evaluate(t)398 expect(input.value).toBe(false)399 })400 test('&&. return false', () => {401 const t = ParseList('(&& false false)')402 const input = Evaluate(t)403 expect(input.value).toBe(false)404 })405 // -------------406 test('||. return true', () => {407 const t = ParseList('(|| true true)')408 const input = Evaluate(t)409 expect(input.value).toBe(true)410 })411 test('||. return false', () => {412 const t = ParseList('(|| false false)')413 const input = Evaluate(t)414 expect(input.value).toBe(false)415 })416 test('||. return true', () => {417 const t = ParseList('(|| true false)')418 const input = Evaluate(t)419 expect(input.value).toBe(true)420 })421 test('||. return true', () => {422 const t = ParseList('(|| false true)')423 const input = Evaluate(t)424 expect(input.value).toBe(true)425 })426})427describe.skip('Conditioning Operators', () => {428 test('condition logic, if then else', () => {429 const t = ParseList('(if (> 2 1) pass)')430 const input = Evaluate(t)431 expect(input.value).toBe('pass')432 })433 test('condition logic, if then else', () => {434 const t = ParseList('(if (< 2 1) pass nope)')435 const input = Evaluate(t)436 expect(input.value).toBe('nope')437 })438 test('condition logic, if then else', () => {439 const t = ParseList('(if (&& (> 2 1) (>= 3 1)) pass nope)')440 const input = Evaluate(t)441 expect(input.value).toBe('pass')442 })443 test('condition logic, if then else', () => {444 const t = ParseList('(if (|| (< 2 1) (<= 3 1)) pass nope)')445 const input = Evaluate(t)446 expect(input.value).toBe('nope')447 })448})449describe.skip("Function", () => {450 test('function throw grammar Error', () => {451 const t = ParseList('(defun () 0)')452 const input = () => { Evaluate(t) }453 expect(input).toThrowError(Error('function does not have enought arguments needs 3 arguments. got=2'))454 })455 test('main function throw grammar Error', () => {456 const t = ParseList('(defun main)')457 const input = () => { Evaluate(t) }458 expect(input).toThrowError(Error('function does not have enought arguments needs 3 arguments. got=1'))459 })460 test('main function throw grammar Error', () => {461 const t = ParseList('(defun)')462 const input = () => { Evaluate(t) }463 expect(input).toThrowError(Error('function does not have enought arguments needs 3 arguments. got=0'))464 })465 test('main function', () => {466 const t = ParseList('(defun main () 0)')467 const input = Evaluate(t)468 expect(input.value).toBe(true)469 })470 test('main function should seccess', () => {471 const t = ParseList('(defun main () 3)')472 const input = Execute(t)473 expect(input.value).toBe(3)474 })475 test('main function should seccess', () => {476 const t = ParseList('(defun main () (+ 1 2))')477 const input = Execute(t)478 expect(input.value).toBe(3)479 })480 test('arbitrary function def within main()', () => {481 const t = ParseList(`482 (defun main ()483 (defun def () 5)484 (fn)485 )486 `)487 const input = Execute(t)488 expect(input.value).toBe(5)489 })...
evaluator.test.ts
Source:evaluator.test.ts
2import { evaluate } from "./evaluator"3import * as types from './types/global'4describe('stdLib operators', () => {5 it('should throw when unknown arithmetic operator is used', async () => {6 const expression = parseList('(! 1 3 4)')7 expect(() => evaluate(expression)).toThrow()8 })9 it('should throw when not enough arguments are passed to arithmetic function', async () => {10 const expression = parseList('(+ 1)')11 expect(() => evaluate(expression)).toThrow()12 })13 test('should evaluate a "+" expression correctly', async () => {14 const expression = parseList('(+ 1 2)')15 const expected = <Atom<number>>{ value: 3 }16 const actual = evaluate(expression)17 expect(actual).toEqual(expected)18 })19 test('should evaluate a "-" expression correctly', async () => {20 const expression = parseList('(- 2 1)')21 const expected = <Atom<number>>{ value: 1 }22 const actual = evaluate(expression)23 expect(actual).toEqual(expected)24 })25 test('should evaluate a "*" expression correctly', async () => {26 const expression = parseList('(* 2 2)')27 const expected = <Atom<number>>{ value: 4 }28 const actual = evaluate(expression)29 expect(actual).toEqual(expected)30 })31 test('should evaluate a "/" expression correctly', async () => {32 const expression = parseList('(/ 4 2)')33 const expected = <Atom<number>>{ value: 2 }34 const actual = evaluate(expression)35 expect(actual).toEqual(expected)36 })37 test('should evaluate a "+" expression with more than 2 args correctly', async () => {38 const expression = parseList('(+ 1 2 3 4)')39 const expected = <Atom<number>>{ value: 10 }40 const actual = evaluate(expression)41 expect(actual).toEqual(expected)42 })43 test('should evaluate an arithmetic expression with nested arithmetic operations correctly', async () => {44 [45 {46 expression: '(+ 1 (+ 1 (+ 2 2)))',47 expected: <Atom<number>>{ value: 6 },48 },49 {50 expression: '(/ 4 (* 1 (+ 1 (- 2 1))))',51 expected: <Atom<number>>{ value: 2 },52 },53 {54 expression: '(/ 4 (* 1 (+ 1 (- 2 1))) 2)',55 expected: <Atom<number>>{ value: 1},56 },57 ].forEach(scenario => {58 const expression = parseList(scenario.expression)59 const actual = evaluate(expression)60 expect(actual).toEqual(scenario.expected)61 })62 })63})64describe('stdLib comparisons', () => {65 describe('==', () => {66 it('should throw if comparison operator "==" is not given 2 arguments', async () => {67 expect(() => evaluate(parseList('(==)'))).toThrow()68 expect(() => evaluate(parseList('(== 1)'))).toThrow()69 })70 it('should successfully run comparison operator "==" when given 2 equal numeric arguments', async () => {71 const actual = evaluate(parseList('(== 1 1)'))72 expect(actual.value).toEqual(true)73 })74 it('should successfully run comparison operator "==" when given 2 unequal numeric arguments', async () => {75 const actual = evaluate(parseList('(== 1 2)'))76 expect(actual.value).toEqual(false)77 })78 })79 describe('eq', () => {80 it('should throw if comparison operator "eq" is not given 2 arguments', async () => {81 expect(() => evaluate(parseList('(eq)'))).toThrow()82 expect(() => evaluate(parseList('(eq 1)'))).toThrow()83 })84 it('should successfully run comparison operator "eq" when given 2 equal numeric arguments', async () => {85 const actual = evaluate(parseList('(eq 1 1)'))86 expect(actual.value).toEqual(true)87 })88 it('should successfully run comparison operator "eq" when given 2 unequal numeric arguments', async () => {89 const actual = evaluate(parseList('(eq 1 2)'))90 expect(actual.value).toEqual(false)91 })92 })93 describe('noteq | !=', () => {94 it('should throw if comparison operator "noteq" is not given 2 arguments', async () => {95 expect(() => evaluate(parseList('(noteq)'))).toThrow()96 expect(() => evaluate(parseList('(noteq 1)'))).toThrow()97 })98 it('should successfully run comparison operator "noteq" when given 2 arguments', async () => {99 [100 { expression: '(noteq 1 2)', expected: true },101 { expression: '(!= 1 2)', expected: true },102 { expression: '(noteq a b)', expected: true },103 { expression: '(!= a b)', expected: true },104 { expression: '(noteq 1 1)', expected: false },105 { expression: '(!= 1 1)', expected: false },106 { expression: '(noteq a a)', expected: false },107 { expression: '(!= a a)', expected: false },108 ].forEach(scenario => {109 const actual = evaluate(parseList(scenario.expression))110 expect(actual.value).toEqual(scenario.expected)111 })112 })113 })114 describe('gt | >', () => {115 it('should throw if comparison operator "gt" or ">" is not given 2 arguments', async () => {116 expect(() => evaluate(parseList('(gt)'))).toThrow()117 expect(() => evaluate(parseList('(gt 1)'))).toThrow()118 expect(() => evaluate(parseList('(>)'))).toThrow()119 expect(() => evaluate(parseList('(> 1)'))).toThrow()120 })121 it('should successfully run comparison operator "gt" or ">" when given 2 numeric arguments', async () => {122 [123 { expression: '(gt 2 1)', expected: true },124 { expression: '(> 2 1)', expected: true },125 { expression: '(gt 1 2)', expected: false },126 { expression: '(> 1 2)', expected: false },127 ].forEach(scenario => {128 const actual = evaluate(parseList(scenario.expression))129 expect(actual.value).toEqual(scenario.expected)130 })131 })132 })133 describe('gte | >=', () => {134 it('should throw if comparison operator "gte" or ">=" is not given 2 arguments', async () => {135 expect(() => evaluate(parseList('(gte)'))).toThrow()136 expect(() => evaluate(parseList('(gte 1)'))).toThrow()137 expect(() => evaluate(parseList('(>=)'))).toThrow()138 expect(() => evaluate(parseList('(>= 1)'))).toThrow()139 })140 it('should successfully run comparison operator "gte" or ">=" when given 2 arguments', async () => {141 [142 { expression: '(gte 2 1)', expected: true },143 { expression: '(gte 2 2)', expected: true },144 { expression: '(>= 2 1)', expected: true },145 { expression: '(>= 2 2)', expected: true },146 { expression: '(gte 1 2)', expected: false },147 { expression: '(>= 1 2)', expected: false },148 ].forEach(scenario => {149 const actual = evaluate(parseList(scenario.expression))150 expect(actual.value).toEqual(scenario.expected)151 })152 })153 })154 describe('lt | <', () => {155 it('should throw if comparison operator "lt" or "<" is not given 2 arguments', async () => {156 expect(() => evaluate(parseList('(lt)'))).toThrow()157 expect(() => evaluate(parseList('(lt 1)'))).toThrow()158 expect(() => evaluate(parseList('(<)'))).toThrow()159 expect(() => evaluate(parseList('(< 1)'))).toThrow()160 })161 it('should successfully run comparison operator "lt" or "<" when given 2 arguments', async () => {162 [163 { expression: '(lt 1 2)', expected: true },164 { expression: '(< 1 2)', expected: true },165 { expression: '(lt 2 1)', expected: false },166 { expression: '(< 2 1)', expected: false },167 { expression: '(< 2 2)', expected: false },168 ].forEach(scenario => {169 const actual = evaluate(parseList(scenario.expression))170 expect(actual.value).toEqual(scenario.expected)171 })172 })173 })174 describe('lte | <=', () => {175 it('should throw if comparison operator "lte" or "<=" is not given 2 arguments', async () => {176 expect(() => evaluate(parseList('(lte)'))).toThrow()177 expect(() => evaluate(parseList('(lte 1)'))).toThrow()178 expect(() => evaluate(parseList('(<=)'))).toThrow()179 expect(() => evaluate(parseList('(<= 1)'))).toThrow()180 })181 it('should successfully run comparison operator "lte" or "<=" when given 2 arguments', async () => {182 [183 { expression: '(lte 1 2)', expected: true },184 { expression: '(<= 1 2)', expected: true },185 { expression: '(lte 1 1)', expected: true },186 { expression: '(<= 1 1)', expected: true },187 { expression: '(<= 2 1)', expected: false },188 { expression: '(<= 2 1)', expected: false },189 ].forEach(scenario => {190 const actual = evaluate(parseList(scenario.expression))191 expect(actual.value).toEqual(scenario.expected)192 })193 })194 })195})196describe('stdLib logical operations', () => {197 describe('and', () => {198 it('should throw when no arguments are given', async () => {199 const expression = parseList('(and)')200 expect(() => evaluate(expression)).toThrow()201 })202 it('should successfully run "and" check when given values', async () => {203 [204 { expression: '(and nil nil ())', expected: false },205 { expression: '(and a nil)', expected: false },206 { expression: '(and a true)', expected: true },207 { expression: '(and a b)', expected: true },208 { expression: '(and (+ 1 1) a)', expected: true },209 ].forEach(scenario => {210 const actual = evaluate(parseList(scenario.expression))211 expect(actual.value).toEqual(scenario.expected)212 })213 })214 })215 describe('or', () => {216 it('should throw when no arguments are given', async () => {217 const expression = parseList('(or)')218 expect(() => evaluate(expression)).toThrow()219 })220 it('should successfully run "or" check when given values', async () => {221 [222 { expression: '(or nil nil)', expected: false },223 // { expression: '(or nil nil ())', expected: false },224 { expression: '(or a nil)', expected: true },225 { expression: '(or a true)', expected: true },226 { expression: '(or a b)', expected: true },227 { expression: '(or (+ 1 1) a)', expected: true },228 ].forEach(scenario => {229 const actual = evaluate(parseList(scenario.expression))230 expect(actual.value).toEqual(scenario.expected)231 })232 })233 })234 describe('not', () => {235 it('should throw when no arguments are given', async () => {236 const expression = parseList('(not)')237 expect(() => evaluate(expression)).toThrow()238 })239 it('should throw when more than 1 argument is given', async () => {240 const expression = parseList('(not (eq 1 1) 1)')241 expect(() => evaluate(expression)).toThrow()242 })243 it('should successfully run "not" check when given a value', async () => {244 [245 { expression: '(not nil)', expected: true },246 // { expression: '(not ())', expected: false },247 { expression: '(not a)', expected: false },248 { expression: '(not true)', expected: false },249 { expression: '(not (+ 1 1))', expected: false },250 { expression: '(not (eq 1 1))', expected: false },251 { expression: '(not (eq 1 2))', expected: true },252 ].forEach(scenario => {253 const actual = evaluate(parseList(scenario.expression))254 expect(actual.value).toEqual(scenario.expected)255 })256 })257 })258})259describe('stdLib conditional functions', () => {260 describe('if', () => {261 it('should throw when unexpected argument lengths are given', async () => {262 [263 '(if)',264 '(if true)',265 '(if nil)',266 '(if nil (+ 1 1) (- 2 1) (eq 1 1))',267 ].forEach(expression => {268 expect(() => evaluate(parseList(expression))).toThrow()269 })270 })271 it('should successfully run "if" condition when given expected arguments', async () => {272 [273 { expression: '(IF nil (+ 1 1))', expected: false },274 { expression: '(IF T (+ 1 1))', expected: 2 },275 { expression: '(if nil (+ 1 1) (eq 1 1))', expected: true },276 { expression: '(if (eq 2 (+ 1 1)) (- 5 3))', expected: 2 },277 { expression: '(if (noteq 2 (+ 1 1)) (- 5 3) (/ 8 2))', expected: 4 },278 { expression: '(if nil (+ 1 1) (- 5 3))', expected: 2 },279 { expression: '(if (+ 1 1) good)', expected: 'good' },280 { expression: '(if (eq 2 1) good bad)', expected: 'bad' },281 ].forEach(scenario => {282 const actual = evaluate(parseList(scenario.expression))283 expect(actual.value).toEqual(scenario.expected)284 })285 })286 })287})288describe('defun', () => {289 it('should throw if "defun" is supplied with less than 2 arguments', async () => {290 [291 '(defun)',292 '(defun testing)',293 ].forEach(expression => {294 expect(() => evaluate(parseList(expression))).toThrow()295 })296 })297 // it('should throw when trying to create a function with a name that already exists', async () => {298 // })299 it('should create a function with the supplied name', async () => {300 [301 { expression: '(defun tester () 2)', args: [], result: 2 },302 ].forEach(scenario => {303 const actual = evaluate(parseList(scenario.expression))304 });305 })...
parser.test.ts
Source:parser.test.ts
...15 })16})17describe('parseList', () => {18 test('should throw error when given unexpected input', () => {19 const actual = () => parseList('')20 expect(actual).toThrow()21 })22 test('should throw if input start and end is invalid', () => {23 const input1 = ' 1 2)'24 const input2 = '(1 2 '25 const actual1 = () => parseList(input1)26 expect(actual1).toThrow()27 const actual2 = () => parseList(input2)28 expect(actual2).toThrow()29 })30 test('should return an empty list when "()" is given', () => {31 const expected = <List>{ items: [] }32 const actual = parseList('()')33 expect(actual).toEqual(expected)34 })35 test('should return a List with one number atom', () => {36 const expected = <List>{ items: [<Atom<number>>{ value: 1 }] }37 const actual = parseList('(1)')38 expect(actual).toEqual(expected)39 })40 test('should return a List with two Atoms', () => {41 const expected = <List>{42 items: [<Atom<number>>{ value: 1 }, <Atom<string>>{ value: 'A' }]43 }44 const actual = parseList('(1 A)')45 expect(actual).toEqual(expected)46 })47 test('should return a List with an Atom, a List of Atoms and an empty list', () => {48 const expected = <List>{49 items: [50 <Atom<string>>{ value: 'A' },51 <List>{ items: [<Atom<number>>{ value: 1 }, <Atom<number>>{ value: 2 }] },52 <List>{ items: [] },53 ],54 }55 const actual = parseList('(A (1 2) ())')56 expect(actual).toEqual(expected)57 })58 test('should return a List when given a symbol and numeric atoms', () => {59 const expected = <List>{60 items: [61 <Atom<string>>{ value: 'add' },62 <Atom<number>>{ value: 1 },63 <Atom<number>>{ value: 2 },64 ],65 }66 const actual = parseList('(add 1 2)')67 expect(actual).toEqual(expected)68 })69 test('should return a nested List of arithmetic expressions', () => {70 const expected = <List>{71 items: [72 <Atom<string>>{ value: '+' },73 <Atom<number>>{ value: 1 },74 <Atom<number>>{ value: 2 },75 <List>{76 items: [77 <Atom<string>>{ value: '*' },78 <Atom<number>>{ value: 3 },79 <Atom<number>>{ value: 4 },80 ]81 },82 ]83 }84 const actual = parseList('(+ 1 2 (* 3 4))')85 expect(actual).toEqual(expected)86 })87 test('should create a deep nested list given a string of arithmetic...', async () => {88 const expected = <List>{89 items: [90 <List>{91 items: [92 <List>{93 items: [94 <Atom<string>>{ value: '+' },95 <Atom<number>>{ value: 1 },96 <Atom<number>>{ value: 2 },97 ]98 }99 ]100 }101 ]102 }103 const actual = parseList('(((+ 1 2)))')104 expect(actual).toEqual(expected)105 })...
Using AI Code Generation
1import React from 'react';2import { storiesOf } from '@storybook/react';3import { action } from '@storybook/addon-actions';4import { linkTo } from '@storybook/addon-links';5import { Button, Welcome } from '@storybook/react/demo';6storiesOf('Welcome', module).add('to Storybook', () => <Welcome showApp={linkTo('Button')} />);7storiesOf('Button', module)8 .add('with text', () => (9 <Button onClick={action('clicked')}>Hello Button</Button>10 .add('with some emoji', () => (11 <Button onClick={action('clicked')}>😀 😎 👍 💯</Button>12 ));13const storyBookRoot = require('storybook-root');14const storyBookRootInstance = new storyBookRoot();15const storyBookRootInstance = new storyBookRoot();16const storyList = storyBookRootInstance.parseList('./test.js');17console.log(storyList);18[ { name: 'Welcome', kind: 'Welcome' },19 { name: 'to Storybook', kind: 'Welcome' },20 { name: 'with text', kind: 'Button' },21 { name: 'with some emoji', kind: 'Button' } ]22import React from 'react';23import { storiesOf } from '@storybook/react';24import { action } from '@storybook/addon-actions';25import { linkTo } from '@storybook/addon-links';26import { Button, Welcome } from '@storybook/react/demo';27storiesOf('Welcome', module).add('to Storybook', () => <Welcome showApp={linkTo('Button')} />);28storiesOf('Button', module)29 .add('with text', () => (30 <Button onClick={action('clicked')}>Hello Button</Button>31 .add('with some emoji', () => (32 <Button onClick={action('clicked')}>😀 😎 👍 💯</Button>33 ));34const storyBookRoot = require('storybook-root');35const storyBookRootInstance = new storyBookRoot();36const storyList = storyBookRootInstance.parseList('./test.js');37console.log(storyList);38[ { name: 'Welcome', kind: 'Welcome' },
Using AI Code Generation
1import { parseList } from 'storybook-root';2const list = parseList('1, 2, 3, 4, 5, 6, 7, 8, 9, 10');3console.log(list);4import { parseList } from 'storybook-root';5const list = parseList('1, 2, 3, 4, 5, 6, 7, 8, 9, 10');6console.log(list);7import { parseList } from 'storybook-root';8const list = parseList('1, 2, 3, 4, 5, 6, 7, 8, 9, 10');9console.log(list);10import { parseList } from 'storybook-root';11const list = parseList('1, 2, 3, 4, 5, 6, 7, 8, 9, 10');12console.log(list);13import { parseList } from 'storybook-root';14const list = parseList('1, 2, 3, 4, 5, 6, 7, 8, 9, 10');15console.log(list);
Using AI Code Generation
1import { parseList } from 'storybook-root';2const parseList = require('storybook-root').parseList;3import { parseList } from 'storybook-root/lib/list';4const parseList = require('storybook-root/lib/list').parseList;5import { parseList } from 'storybook-root/lib/list/index';6const parseList = require('storybook-root/lib/list/index').parseList;7import { parseList } from 'storybook-root/lib/list/index.js';8const parseList = require('storybook-root/lib/list/index.js').parseList;9import { parseList } from 'storybook-root/lib/list/index.cjs';10const parseList = require('storybook-root/lib/list/index.cjs').parseList;11import { parseList } from 'storybook-root/lib/list/index.cjs.js';12const parseList = require('storybook-root/lib/list/index.cjs.js').parseList;13import { parseList } from 'storybook-root/lib/list/index.mjs';14const parseList = require('storybook-root/lib/list/index.mjs').parseList;15import { parseList } from 'storybook-root/lib/list/index.mjs.js';16const parseList = require('storybook-root/lib/list/index.mjs.js').parseList;17import { parseList } from 'storybook-root/lib/list/index.ts';
Using AI Code Generation
1const { parseList } = require('storybook-root')2const list = parseList('a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z')3console.log(list)4const { parseList } = require('storybook-root')5const list = parseList('a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z')6console.log(list)7const { parseList } = require('storybook-root')8const list = parseList('a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z')9console.log(list)10const { parseList } = require('storybook-root')11const list = parseList('a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z')12console.log(list)13const { parseList } = require('storybook-root')14const list = parseList('a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z')15console.log(list)16const { parseList } = require('storybook-root')17const list = parseList('a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z')18console.log(list)19const { parseList } = require('storybook-root')20const list = parseList('a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z')21console.log(list)22const { parseList } = require('storybook-root')23const list = parseList('a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t
Using AI Code Generation
1import { parseList } from 'storybook-root';2const list = parseList('1,2,3,4,5,6');3console.log(list);4const path = require('path');5module.exports = (baseConfig, env, config) => {6 config.resolve.alias['storybook-root'] = path.resolve(__dirname, '../');7 return config;8};9import { configure } from '@storybook/react';10import { setOptions } from '@storybook/addon-options';11import { withInfo } from '@storybook/addon-info';12import { setDefaults } from 'storybook-root';13setDefaults();14setOptions({
Using AI Code Generation
1import storybookRoot from './storybook-root.vue';2const storybookRootInstance = new storybookRoot();3storybookRootInstance.parseList();4import storybookRoot from './storybook-root.vue';5import storybookRoot from './storybook-root.vue';6const storybookRootInstance = new storybookRoot();7storybookRootInstance.parseList();8import storybookRoot from './storybook-root.vue';9import storybookRoot from './storybook-root.vue';10const storybookRootInstance = new storybookRoot();11storybookRootInstance.parseList();12import storybookRoot from './storybook-root.vue';13import storybookRoot from './storybook-root.vue';14const storybookRootInstance = new storybookRoot();15storybookRootInstance.parseList();16import storybookRoot from './storybook-root.vue';17import storybookRoot from './storybook-root.vue';18const storybookRootInstance = new storybookRoot();19storybookRootInstance.parseList();20import storybookRoot from './storybook-root.vue';21import storybookRoot from './storybook-root.vue';22const storybookRootInstance = new storybookRoot();23storybookRootInstance.parseList();24import storybookRoot from './storybook-root.vue';25import storybookRoot from './storybook-root.vue';26const storybookRootInstance = new storybookRoot();27storybookRootInstance.parseList();28import storybookRoot from './storybook-root.vue';29import
Using AI Code Generation
1var storybook = require('storybook-root');2var storybook = new Storybook();3storybook.parseList('path/to/storybook/list.txt', function(err, stories) {4 if (err) {5 console.log(err);6 }7 else {8 console.log(stories);9 }10});11var storybook = require('storybook-root');12var storybook = new Storybook();13storybook.parseList('path/to/storybook/list.txt', function(err, stories) {14 if (err) {15 console.log(err);16 }17 else {18 console.log(stories);19 }20});21var storybook = require('storybook-root');22var storybook = new Storybook();23storybook.parseList('path/to/storybook/list.txt', function(err, stories) {24 if (err) {25 console.log(err);26 }27 else {28 console.log(stories);29 }30});31var storybook = require('storybook-root');32var storybook = new Storybook();33storybook.parseList('path/to/storybook/list.txt', function(err, stories) {34 if (err) {35 console.log(err);36 }37 else {38 console.log(stories);39 }40});41var storybook = require('storybook-root');42var storybook = new Storybook();43storybook.parseList('path/to/storybook/list.txt', function(err, stories) {44 if (err) {45 console.log(err);46 }47 else {48 console.log(stories);49 }50});51var storybook = require('storybook-root');52var storybook = new Storybook();53storybook.parseList('path/to/storybook/list.txt', function(err, stories) {54 if (err) {55 console.log(err);56 }57 else {58 console.log(stories);59 }60});
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!