Esempio n. 1
0
    def test_cmp_different_string(self):
        s1 = SingleString("abc", SingleString.TYPE_STRING)
        s2 = SingleString("ab", SingleString.TYPE_STRING)
        eq_(cmp(s1, s2), 1)

        s1 = SingleString("ab", SingleString.TYPE_STRING)
        s2 = SingleString("abc", SingleString.TYPE_STRING)
        eq_(cmp(s1, s2), -1)
Esempio n. 2
0
    def test_split_string_and_number(self):
        result = ComplexString("B1").split()
        eq_(result, [SingleString("B", SingleString.TYPE_STRING),
                     SingleString("1", SingleString.TYPE_NUMBER)])

        result = ComplexString("B01").split()
        eq_(result, [SingleString("B", SingleString.TYPE_STRING),
                     SingleString("01", SingleString.TYPE_NUMBER)])
Esempio n. 3
0
    def test_split_escape_string_and_number(self):
        result = ComplexString(r"\B1").split()
        eq_(result, [SingleString("B1", SingleString.TYPE_NUMBER)])

        result = ComplexString(r"1\B1").split()
        eq_(result, [SingleString("1B1", SingleString.TYPE_NUMBER)])

        result = ComplexString(r"1\B\B1").split()
        eq_(result, [SingleString("1BB1", SingleString.TYPE_NUMBER)])
Esempio n. 4
0
    def test_split_string_and_escape_number(self):
        result = ComplexString(r"B\1").split()
        eq_(result, [SingleString("B1", SingleString.TYPE_STRING)])

        result = ComplexString(r"B\123B").split()
        eq_(result, [SingleString("B123B", SingleString.TYPE_STRING)])

        result = ComplexString(r"\1B").split()
        eq_(result, [SingleString("1B", SingleString.TYPE_STRING)])
Esempio n. 5
0
    def _combine_single_strings(self, single_strings):
        self.single_strings = []

        single = None
        for s in single_strings:
            if single is None:
                single = SingleString(s.str, s.type)
            elif s.type == single.type:
                single.str += s.str
            else:
                self.single_strings.append(single)
                single = SingleString(s.str, s.type)
        else:
            if single is not None:
                self.single_strings.append(single)
Esempio n. 6
0
    def _read_normal_number(self, begin):
        for i in range(begin + 1, self.len):
            if not self.str[i].isdigit():
                end = i
                break
        else:
            end = self.len

        return SingleString(self.str[begin:end], SingleString.TYPE_NUMBER), end
Esempio n. 7
0
    def _read_normal_string(self, begin):
        for i in range(begin + 1, self.len):
            if not self.str[i].isalpha():
                end = i
                break
        else:
            end = self.len

        return SingleString(self.str[begin:end], SingleString.TYPE_STRING), end
Esempio n. 8
0
    def test_split_string_escape_numbers_and_number(self):
        result = ComplexString(r"B\1234").split()
        eq_(result, [SingleString("B123", SingleString.TYPE_STRING),
                     SingleString("4", SingleString.TYPE_NUMBER)])

        result = ComplexString(r"B\1B1").split()
        eq_(result, [SingleString("B1B", SingleString.TYPE_STRING),
                     SingleString("1", SingleString.TYPE_NUMBER)])

        result = ComplexString(r"B\1234\1B").split()
        eq_(result, [SingleString("B123", SingleString.TYPE_STRING),
                     SingleString("4", SingleString.TYPE_NUMBER),
                     SingleString("1B", SingleString.TYPE_STRING)])

        result = ComplexString(r"B\1\2345\1B").split()
        eq_(result, [SingleString("B1234", SingleString.TYPE_STRING),
                     SingleString("5", SingleString.TYPE_NUMBER),
                     SingleString("1B", SingleString.TYPE_STRING)])
Esempio n. 9
0
    def _read_escape_number(self, begin):
        max_len = 3

        for i in range(begin, self.len):
            if (not self.str[i].isdigit()) or (max_len == 0):
                end = i
                break
            else:
                max_len -= 1
        else:
            end = self.len

        return SingleString(self.str[begin:end], SingleString.TYPE_STRING), end
Esempio n. 10
0
    def test_cmp_number_and_string(self):
        s1 = SingleString("01", SingleString.TYPE_NUMBER)
        s2 = SingleString("ab", SingleString.TYPE_STRING)
        eq_(cmp(s1, s2), -1)

        s1 = SingleString("ab", SingleString.TYPE_STRING)
        s2 = SingleString("01", SingleString.TYPE_NUMBER)
        eq_(cmp(s1, s2), 1)

        s1 = SingleString("01", SingleString.TYPE_NUMBER)
        s2 = SingleString("01", SingleString.TYPE_STRING)
        eq_(cmp(s1, s2), -1)

        s1 = SingleString("01", SingleString.TYPE_STRING)
        s2 = SingleString("01", SingleString.TYPE_NUMBER)
        eq_(cmp(s1, s2), 1)
Esempio n. 11
0
 def _read_escape_string(self, begin):
     end = begin + 1
     return SingleString(self.str[begin:end], SingleString.TYPE_NUMBER), end
Esempio n. 12
0
    def test_cmp_different_number(self):
        s1 = SingleString("01", SingleString.TYPE_NUMBER)
        s2 = SingleString("1", SingleString.TYPE_NUMBER)
        eq_(cmp(s1, s2), 1)

        s1 = SingleString("1", SingleString.TYPE_NUMBER)
        s2 = SingleString("01", SingleString.TYPE_NUMBER)
        eq_(cmp(s1, s2), -1)

        s1 = SingleString("1", SingleString.TYPE_NUMBER)
        s2 = SingleString("2", SingleString.TYPE_NUMBER)
        eq_(cmp(s1, s2), -1)

        s1 = SingleString("2", SingleString.TYPE_NUMBER)
        s2 = SingleString("1", SingleString.TYPE_NUMBER)
        eq_(cmp(s1, s2), 1)

        s1 = SingleString("1A0", SingleString.TYPE_NUMBER)
        s2 = SingleString("750", SingleString.TYPE_NUMBER)
        eq_(cmp(s1, s2), 0)

        s1 = SingleString("A", SingleString.TYPE_NUMBER)
        s2 = SingleString("65", SingleString.TYPE_NUMBER)
        eq_(cmp(s1, s2), -1)

        s1 = SingleString("65", SingleString.TYPE_NUMBER)
        s2 = SingleString("A", SingleString.TYPE_NUMBER)
        eq_(cmp(s1, s2), 1)

        s1 = SingleString("B", SingleString.TYPE_NUMBER)
        s2 = SingleString("65", SingleString.TYPE_NUMBER)
        eq_(cmp(s1, s2), 1)

        s1 = SingleString("65", SingleString.TYPE_NUMBER)
        s2 = SingleString("B", SingleString.TYPE_NUMBER)
        eq_(cmp(s1, s2), -1)
Esempio n. 13
0
 def test_cmp_same_number(self):
     s1 = SingleString("1", SingleString.TYPE_NUMBER)
     s2 = SingleString("1", SingleString.TYPE_NUMBER)
     eq_(cmp(s1, s2), 0)
Esempio n. 14
0
 def test_cmp_same_string(self):
     s1 = SingleString("ab", SingleString.TYPE_STRING)
     s2 = SingleString("ab", SingleString.TYPE_STRING)
     eq_(cmp(s1, s2), 0)
Esempio n. 15
0
 def test_split_only_number(self):
     result = ComplexString("1").split()
     eq_(result, [SingleString("1", SingleString.TYPE_NUMBER)])
Esempio n. 16
0
 def test_split_only_string(self):
     result = ComplexString("B").split()
     eq_(result, [SingleString("B", SingleString.TYPE_STRING)])