Пример #1
0
 def test_write(self):
     with StringIO() as stream:
         text1 = "a"
         text2 = "b"
         text3 = "c"
         node = SentenceNode()
         node.add(TextNode(text1))
         node.add(TextNode(text2))
         node.add(TextNode(text3))
         node.write(stream)
         self.assertEqual(stream.getvalue(), text1 + text2 + text3)
Пример #2
0
 def test_write(self):
     with StringIO() as stream:
         separator = TextNode(",")
         scope = Scope()
         variable = VariableNode("a", scope)
         variable.set_value(["a", "b", "c"])
         node = JoinNode(separator, variable)
         node.write(stream)
         self.assertEqual(stream.getvalue(), "a,b,c")
Пример #3
0
 def test_write(self):
     scope = Scope()
     variable = VariableNode("a", scope)
     thennode = TextNode("true")
     elsenode = TextNode("false")
     ifnode = IfNode(variable, thennode, elsenode)
     # when undefined
     with StringIO() as stream:
         ifnode.write(stream)
         self.assertEqual(stream.getvalue(), "false")
     # when true
     variable.set_value(True)
     with StringIO() as stream:
         ifnode.write(stream)
         self.assertEqual(stream.getvalue(), "true")
     # when false
     variable.set_value(False)
     with StringIO() as stream:
         ifnode.write(stream)
         self.assertEqual(stream.getvalue(), "false")
Пример #4
0
def read_text(preread, stream, parser):
    with StringIO() as readstr:
        readstr.write(preread)
        while True:
            character = stream.peek()
            if not character:
                break
            if parser.is_syntax_character(character):
                break
            readstr.write(character)
            stream.get()
        return TextNode(readstr.getvalue())
Пример #5
0
def read_at(preread, stream, parser):
    return TextNode("@")
Пример #6
0
def read_in(preread, stream, parser):
    if stream.read(2) != "in":
        raise SyntaxError("could not read \"in\".")
    return TextNode("")
Пример #7
0
def read_close_paren(preread, stream, parser):
    read_whitespace("", stream, parser)
    if stream.read(3) != "-->":
        raise SyntaxError("could not read \"-->\".")
    return TextNode("")
Пример #8
0
 def test_write(self):
     content = "this is text nodes content."
     node = TextNode(content)
     with StringIO() as stream:
         node.write(stream)
         self.assertEqual(stream.getvalue(), content)  # test