def test_quasiquote(self): assert p("`1") == pair(sym('quasiquote'), pair(1, None)) assert p("`,1") == pair(sym('quasiquote'), pair(pair(sym('unquote'), pair(1, None)), None)) assert p("`(1 ,(+ 1 5) ,@(list 1 2))") == \ pair(sym("quasiquote"), pair(pair(1, pair(pair(sym("unquote"), pair(pair(sym("+"), pair(1, pair(5, None))), None)), pair(pair(sym("unquote-slicing"), pair(pair(sym("list"), pair(1, pair(2, None))), None)), None))), None))
def test_string(self): assert p('"foo"') == "foo" assert p(r'"foo\"bar"') == 'foo"bar' assert p(r'"foo\"bar\""') == 'foo"bar"' assert p(r'""') == '' assert p(r'"tab\t"') == 'tab\t' assert p(r'"newline\n"') == 'newline\n'
def test_complex(self): assert p('0+i') == 1j assert p('5+3i') == 5+3j assert p('6-2i') == 6-2j assert p('3.5-4i') == 3.5-4j assert p('0.3+0.5i') == 0.3+0.5j assert p('0.5+0i') == 0.5
def test_rational(self): assert p('6/3') == 2 assert_almost_equal(p('1/3'), 1.0/3)
def test_float(self): assert_almost_equal(p('0.0'), 0.0) assert_almost_equal(p('-0.0'), 0.0) assert_almost_equal(p('2.5'), 2.5) assert_almost_equal(p('-200.75'), -200.75)
def test_integer(self): assert p('0') == 0 assert p('5') == 5 assert p('+10') == 10 assert p('-10') == -10
def test_list(self): assert p('(1 2 3)') == pair(1, pair(2, pair(3, None))) assert p('(1)') == pair(1, None) assert p('()') == None assert p('(1 2 3 4)') == pair(1, pair(2, pair(3, pair(4, None))))
def test_quote(self): assert p("'1") == pair(sym('quote'), pair(1, None)) assert p("''1") == pair(sym('quote'), pair(pair(sym('quote'), pair(1, None)), None))
def test_pair(self): assert p('(1 . 2)') == pair(1, 2) assert p('(1 .2)') == pair(1, 2) assert p('(1 2 . 3)') == pair(1, pair(2, 3))
def test_list(self): assert p('(1 2 3)') == pair(1, pair(2, pair(3, None))) assert p('(1)') == pair(1, None) assert p('()') == None
def test_bool(self): assert p('#t') == True assert p('#f') == False
def test_symbol(self): assert p('foo') == sym('foo') assert p('foo123') == sym('foo123') assert p('string->number') == sym('string->number') assert p('number?') == sym('number?') assert p('...') == sym('...')
def test_comment(self): assert p("; this is a comment\n5") == 5 assert p("; this is a comment\n 5") == 5 assert p("5; this is a comment") == 5 assert p("5; this is a comment\n") == 5