Esempio n. 1
0
    def test_bindings(self):
        with peg:
            short = ("omg" is wtf) >> wtf * 2
            medium = ("omg" is o, " ", "wtf" is w, " ",
                      "bb+q".r is b) >> o + w + b
            seq1 = ("l", ("ol".rep1) is xxx) >> xxx
            seq2 = ("l", ("ol" is xxx).rep1) >> xxx
            seq3 = ("l", ("ol" is xxx).rep1) >> sum(map(len, xxx))
        with require:
            short.parse_string('omg').output == 'omgomg'
            short.parse_string('omgg').index == 3
            short.parse_string('cow').index == 0
            medium.parse_string('omg wtf bbq').output == 'omgwtfbbq'
            medium.parse_string('omg wtf bbbbbq').output == 'omgwtfbbbbbq'
            medium.parse_string('omg wtf bbqq').index == 11
            seq3.parse_string("lolololol").output == 8

        for x in ["lol", "lolol", "ol", "'"]:
            if type(seq1.parse_string(x)) is Success:

                require(
                    seq1.parse_string(x).output == seq2.parse_string(x).output)
            else:

                require(
                    seq1.parse_string(x).index == seq2.parse_string(x).index)
Esempio n. 2
0
    def test_require(self):
        with self.assertRaises(AssertionError) as cm:
            require(1 == 10)

        assert cm.exception.message == "Require Failed\n1 == 10 -> False"

        require % (1 == 1)

        with self.assertRaises(AssertionError) as cm:
            require % (3**2 + 4**2 != 5**2)

        require % (3**2 + 4**2 == 5**2)
Esempio n. 3
0
        def test_require(self):
            with self.assertRaises(AssertionError) as cm:
                require(1 == 10)

            assert cm.exception.message == "Require Failed\n1 == 10 -> False"

            require%(1 == 1)

            with self.assertRaises(AssertionError) as cm:
                require%(3**2 + 4**2 != 5**2)


            require%(3**2 + 4**2 == 5**2)
Esempio n. 4
0
File: peg.py Progetto: jjpe/macropy
    def test_bindings(self):
        with peg:
            short = ("omg" is wtf) >> wtf * 2
            medium = ("omg" is o, " ", "wtf" is w, " ", "bb+q".r is b) >> o + w + b
            seq1 = ("l", ("ol".rep1) is xxx) >> xxx
            seq2 = ("l", ("ol" is xxx).rep1) >> xxx
            seq3 = ("l", ("ol" is xxx).rep1) >> sum(map(len, xxx))
        with require:
            short.parse_string('omg').output == 'omgomg'
            short.parse_string('omgg').index == 3
            short.parse_string('cow').index == 0
            medium.parse_string('omg wtf bbq').output == 'omgwtfbbq'
            medium.parse_string('omg wtf bbbbbq').output == 'omgwtfbbbbbq'
            medium.parse_string('omg wtf bbqq').index == 11
            seq3.parse_string("lolololol").output == 8

        for x in ["lol", "lolol", "ol", "'"]:
            if type(seq1.parse_string(x)) is Success:

                require(seq1.parse_string(x).output == seq2.parse_string(x).output)
            else:

                require(seq1.parse_string(x).index == seq2.parse_string(x).index)