# Path: pycell/compile_.py
# def compile_(output, filename):
#     env = Env()
#     with open(output, "w") as outfile:
#         outfile.write(
#             compile_list(parse(lex(pycell.library.as_text(env))), env))
#         with open(filename, encoding="ascii") as infile:
#             outfile.write(
#                 compile_list(parse(lex(chars_in_file(infile))), env))
# 
# Path: pycell/env.py
# class Env:
#     def __init__(self, parent=None, stdin=None, stdout=None, stderr=None):
#         """
#         Supply _either_ std{in,out,err} _or_ parent, not both.
#         """
#         self.stdin = stdin
#         self.stdout = stdout
#         self.stderr = stderr
#         self.parent = parent
#         if parent is not None:
#             assert stdin is None
#             assert stdout is None
#             assert stderr is None
#             self.stdin = parent.stdin
#             self.stdout = parent.stdout
#             self.stderr = parent.stderr
#         self.items = {}
# 
#     def get(self, name):
#         if name in self.items:
#             return self.items[name]
#         elif self.parent is not None:
#             return self.parent.get(name)
#         else:
#             return None
# 
#     def set(self, name, value):
#         self.items[name] = value
# 
#     def contains(self, name):
#         return name in self.items
# 
#     def __str__(self):
#         ret = ""
#         for k, v in self.items.items():
#             ret += "%s=%s\n" % (k, v)
#         ret += ".\n" + str(self.parent)
#         return ret
# 
# Path: pycell/eval_.py
# def eval_list(exprs, env):
#     ret = ("none",)
#     for expr in eval_iter(exprs, env):
#         ret = expr
#     return ret
# 
# Path: pycell/lexer.py
# def lex(chars_iter):
#     chars = PeekableStream(chars_iter)
#     while chars.next is not None:
#         c = chars.move_next()
#         if c in " \n":              pass           # Ignore white space
#         elif c in "(){},;=:":       yield (c, "")  # Special characters
#         elif c in "+-*/":           yield ("operation", c)
#         elif c in ("'", '"'):       yield ("string", _scan_string(c, chars))
#         elif re.match("[.0-9]", c): yield ("number", _scan(c, chars, "[.0-9]"))
#         elif re.match("[_a-zA-Z]", c):
#             yield ("symbol", _scan(c, chars, "[_a-zA-Z0-9]"))
#         elif c == "\t":
#             raise Exception("Tab characters are not allowed in Cell.")
#         else:
#             raise Exception("Unrecognised character: '" + c + "'.")
# 
# Path: pycell/parser.py
# def parse(tokens_iterator):
#     parser = Parser(PeekableStream(tokens_iterator), ";")
#     while parser.tokens.next is not None:
#         p = parser.next_expression(None)
#         if p is not None:
#             yield p
#         parser.tokens.move_next()
# 
# Path: tests/util/asserts.py
# def assert_that(obj, matcher):
#     assert_implements(obj, object)
#     assert_implements(matcher, Matcher)
#     if not matcher.matches(obj):
#         raise AssertionError(matcher.description())
# 
# def equals(expected):
#     class EqualsMatcher:
# 
#         def __init__(self, expected):
#             self.expected = expected
# 
#         def matches(self, actual):
#             self.actual = actual
#             return actual == expected
# 
#         def description(self):
#             ret = (
#                 repr(self.actual)
#                 + " does not equal "
#                 + repr(self.expected)
#                 + " as expected."
#             )
#             if len(ret) > 80:
#                 ret = """Values are not equal (actual then expected):
# %s
# %s
# """ % ( repr(self.actual), repr(self.expected))
#             return ret
#     return EqualsMatcher(expected)
# 
# Path: tests/util/test.py
# def test(t):
#     return TestFunctionType(t)
# 
# Path: tests/util/system_test.py

# 
# Path: tests/util/all_examples.py
# def all_examples(file_ext=".cell"):
#     return (
#         "examples/" + filename
#         for filename in os.listdir("examples")
#         if filename.endswith(file_ext)
#     )


from io import StringIO
from pycell.compile_ import compile_
from pycell.env import Env
from pycell.eval_ import eval_list
from pycell.lexer import lex
from pycell.parser import parse
from tests.util.asserts import assert_that, equals
from tests.util.test import test
from tests.util.system_test import system_test
from tests.util.all_examples import all_examples
    from pycell.run import run
    from subprocess import check_output
    from pycell.chars_in_file import chars_in_file
    from pycell.compile_ import compile_list
import pycell.library
    import os
            };

        num1 = 3;
        num2 = double( num1 );

        answer =
            if( equals( num2, 6 ),
                {"LARGE!"},
                {"small."}
            );

        answer;
    """
    assert_that(runned(example), equals(("string", "LARGE!")))


@system_test
def All_examples_evaluate():
    for example in all_examples():
        try:
            with StringIO() as stdin, StringIO() as stdout:
                run(example, stdin, stdout, stdout)
                with open(example[:-5] + ".output.txt") as outputfile:
                    assert_that(stdout.getvalue(), equals(outputfile.read()))
        except Exception as e:
            raise Exception("%s: %s" % (example, str(e)))


@system_test
def All_examples_work_in_js():

# Path: pycell/compile_.py
# def compile_(output, filename):
#     env = Env()
#     with open(output, "w") as outfile:
#         outfile.write(
#             compile_list(parse(lex(pycell.library.as_text(env))), env))
#         with open(filename, encoding="ascii") as infile:
#             outfile.write(
#                 compile_list(parse(lex(chars_in_file(infile))), env))
# 
# Path: pycell/env.py
# class Env:
#     def __init__(self, parent=None, stdin=None, stdout=None, stderr=None):
#         """
#         Supply _either_ std{in,out,err} _or_ parent, not both.
#         """
#         self.stdin = stdin
#         self.stdout = stdout
#         self.stderr = stderr
#         self.parent = parent
#         if parent is not None:
#             assert stdin is None
#             assert stdout is None
#             assert stderr is None
#             self.stdin = parent.stdin
#             self.stdout = parent.stdout
#             self.stderr = parent.stderr
#         self.items = {}
# 
#     def get(self, name):
#         if name in self.items:
#             return self.items[name]
#         elif self.parent is not None:
#             return self.parent.get(name)
#         else:
#             return None
# 
#     def set(self, name, value):
#         self.items[name] = value
# 
#     def contains(self, name):
#         return name in self.items
# 
#     def __str__(self):
#         ret = ""
#         for k, v in self.items.items():
#             ret += "%s=%s\n" % (k, v)
#         ret += ".\n" + str(self.parent)
#         return ret
# 
# Path: pycell/eval_.py
# def eval_list(exprs, env):
#     ret = ("none",)
#     for expr in eval_iter(exprs, env):
#         ret = expr
#     return ret
# 
# Path: pycell/lexer.py
# def lex(chars_iter):
#     chars = PeekableStream(chars_iter)
#     while chars.next is not None:
#         c = chars.move_next()
#         if c in " \n":              pass           # Ignore white space
#         elif c in "(){},;=:":       yield (c, "")  # Special characters
#         elif c in "+-*/":           yield ("operation", c)
#         elif c in ("'", '"'):       yield ("string", _scan_string(c, chars))
#         elif re.match("[.0-9]", c): yield ("number", _scan(c, chars, "[.0-9]"))
#         elif re.match("[_a-zA-Z]", c):
#             yield ("symbol", _scan(c, chars, "[_a-zA-Z0-9]"))
#         elif c == "\t":
#             raise Exception("Tab characters are not allowed in Cell.")
#         else:
#             raise Exception("Unrecognised character: '" + c + "'.")
# 
# Path: pycell/parser.py
# def parse(tokens_iterator):
#     parser = Parser(PeekableStream(tokens_iterator), ";")
#     while parser.tokens.next is not None:
#         p = parser.next_expression(None)
#         if p is not None:
#             yield p
#         parser.tokens.move_next()
# 
# Path: tests/util/asserts.py
# def assert_that(obj, matcher):
#     assert_implements(obj, object)
#     assert_implements(matcher, Matcher)
#     if not matcher.matches(obj):
#         raise AssertionError(matcher.description())
# 
# def equals(expected):
#     class EqualsMatcher:
# 
#         def __init__(self, expected):
#             self.expected = expected
# 
#         def matches(self, actual):
#             self.actual = actual
#             return actual == expected
# 
#         def description(self):
#             ret = (
#                 repr(self.actual)
#                 + " does not equal "
#                 + repr(self.expected)
#                 + " as expected."
#             )
#             if len(ret) > 80:
#                 ret = """Values are not equal (actual then expected):
# %s
# %s
# """ % ( repr(self.actual), repr(self.expected))
#             return ret
#     return EqualsMatcher(expected)
# 
# Path: tests/util/test.py
# def test(t):
#     return TestFunctionType(t)
# 
# Path: tests/util/system_test.py

# 
# Path: tests/util/all_examples.py
# def all_examples(file_ext=".cell"):
#     return (
#         "examples/" + filename
#         for filename in os.listdir("examples")
#         if filename.endswith(file_ext)
#     )


# Path: tests/run_tests.py
from io import StringIO
from pycell.compile_ import compile_
from pycell.env import Env
from pycell.eval_ import eval_list
from pycell.lexer import lex
from pycell.parser import parse
from tests.util.asserts import assert_that, equals
from tests.util.test import test
from tests.util.system_test import system_test
from tests.util.all_examples import all_examples
    from pycell.run import run
    from subprocess import check_output
    from pycell.chars_in_file import chars_in_file
    from pycell.compile_ import compile_list
import pycell.library
    import os

            };

        num1 = 3;
        num2 = double( num1 );

        answer =
            if( equals( num2, 6 ),
                {"LARGE!"},
                {"small."}
            );

        answer;
    """
    assert_that(runned(example), equals(("string", "LARGE!")))


@system_test
def All_examples_evaluate():
    for example in all_examples():
        try:
            with StringIO() as stdin, StringIO() as stdout:
                run(example, stdin, stdout, stdout)
                with open(example[:-5] + ".output.txt") as outputfile:
                    assert_that(stdout.getvalue(), equals(outputfile.read()))
        except Exception as e:
            raise Exception("%s: %s" % (example, str(e)))


@system_test
def All_examples_work_in_js():

    for example in all_examples():