def test_nested_applications(self): exp = unlambda.Application(unlambda.Application(unlambda.S, unlambda.K), unlambda.I) self.assertEqual(exp, unlambda._parse('``ski')) exp = unlambda.Application(unlambda.Application(unlambda.Dot('s'), unlambda.Dot('k')), unlambda.Application(unlambda.Dot('i'), unlambda.Dot('v'))) self.assertEqual(exp, unlambda._parse('``.s.k`.i.v')) exp = unlambda.Application( unlambda.Application( unlambda.D, unlambda.Application(unlambda.Dot('*'), unlambda.I)), unlambda.Application(unlambda.Dot('+'), unlambda.I)) self.assertEqual(exp, unlambda._parse('``d`.*i`.+i')) self.assertNotEqual(unlambda._parse('``skk'), unlambda._parse('`s`kk'))
def test_nested_applications(self): exp = unlambda.Application( unlambda.Application(unlambda.S, unlambda.K), unlambda.I) self.assertEqual(exp, unlambda._parse('``ski')) exp = unlambda.Application( unlambda.Application(unlambda.Dot('s'), unlambda.Dot('k')), unlambda.Application(unlambda.Dot('i'), unlambda.Dot('v'))) self.assertEqual(exp, unlambda._parse('``.s.k`.i.v')) exp = unlambda.Application( unlambda.Application( unlambda.D, unlambda.Application(unlambda.Dot('*'), unlambda.I)), unlambda.Application(unlambda.Dot('+'), unlambda.I)) self.assertEqual(exp, unlambda._parse('``d`.*i`.+i')) self.assertNotEqual(unlambda._parse('``skk'), unlambda._parse('`s`kk'))
def test_whitespace(self): """whitespace and comments are the same thing as we all know""" exp = unlambda.Dot(' ') self.assertEqual(exp, unlambda._parse('. ')) exp = unlambda.Dot('#') self.assertEqual(exp, unlambda._parse('.#')) self.assertRaises(IndexError, unlambda._parse, '`. #') self.assertEqual(unlambda._parse('``skk'), unlambda._parse('` \t \t ` \ns\n\nk\t k ')) self.assertEqual(unlambda._parse('``skk'), unlambda._parse('\t #hello world ``ee\r\n`#lorem\r\n #ipsum\r\n ` # do # lor \r\n#skk\r\nskk'))
def test_simple_applications(self): exp = unlambda.Application(unlambda.S, unlambda.K) self.assertEqual(exp, unlambda._parse('`sk')) exp = unlambda.Application(unlambda.Dot('*'), unlambda.C) self.assertEqual(exp, unlambda._parse('`.*c')) exp = unlambda.Application(unlambda.C, unlambda.Dot('s')) self.assertEqual(exp, unlambda._parse('`c.s')) exp = unlambda.Application(unlambda.D, unlambda.D) self.assertEqual(exp, unlambda._parse('`dd')) self.assertNotEqual(unlambda._parse('`ik'), unlambda._parse('`ki')) self.assertRaises(IndexError, unlambda._parse, '`k') self.assertRaises(ValueError, unlambda._parse, '`kf')
def test_whitespace(self): """whitespace and comments are the same thing as we all know""" exp = unlambda.Dot(' ') self.assertEqual(exp, unlambda._parse('. ')) exp = unlambda.Dot('#') self.assertEqual(exp, unlambda._parse('.#')) self.assertRaises(IndexError, unlambda._parse, '`. #') self.assertEqual(unlambda._parse('``skk'), unlambda._parse('` \t \t ` \ns\n\nk\t k ')) self.assertEqual( unlambda._parse('``skk'), unlambda._parse( '\t #hello world ``ee\r\n`#lorem\r\n #ipsum\r\n ` # do # lor \r\n#skk\r\nskk' ))
def _assertNotYields(self, code, value, input=''): in_ = StringIO(input) self.assertNotEqual(unlambda.run_program(code, input_=in_), unlambda._parse(value))
def _assertPrints(self, code, output, input=''): out = StringIO() in_ = StringIO(input) unlambda._run(unlambda._parse(code), output=out, input_=in_) self.assertEqual(out.getvalue(), output)
def test_primitives(self): self.assertEqual(unlambda.I, unlambda._parse('i')) self.assertEqual(unlambda.S, unlambda._parse('s')) self.assertEqual(unlambda.K, unlambda._parse('k')) self.assertEqual(unlambda.V, unlambda._parse('v')) self.assertEqual(unlambda.D, unlambda._parse('d')) self.assertEqual(unlambda.Dot('*'), unlambda._parse('.*')) self.assertEqual(unlambda.R, unlambda._parse('r')) self.assertEqual(unlambda.E, unlambda._parse('e')) self.assertNotEqual(unlambda.I, unlambda._parse('.*')) self.assertNotEqual(unlambda.R, unlambda._parse('.\n')) self.assertRaises(IndexError, unlambda._parse, '.') self.assertRaises(ValueError, unlambda._parse, 'f') self.assertEqual(unlambda.C, unlambda._parse('c')) self.assertEqual(unlambda.At, unlambda._parse('@')) self.assertEqual(unlambda.Pipe, unlambda._parse('|')) self.assertEqual(unlambda.QuestionMark('x'), unlambda._parse('?x'))