class X: def __init__(self, Name): sh = StringIO("[:\\P{Script=%s}:]" % Name) self.name = Name self.charset = regex.snap_set_expression(sh, {}) self.sm = StateMachine() self.sm.add_transition(self.sm.init_state_index, self.charset, AcceptanceF=True) self.id = self.sm.get_id() def check(self, SM): """This function throws an exception as soon as one single value is not matched according to the expectation. """ print "Name = " + self.name, for interval in self.charset.get_intervals(PromiseToTreatWellF=True): for i in range(interval.begin, interval.end): utf8_seq = unicode_to_utf8(i) # Apply sequence to state machine s_idx = result.init_state_index for byte in utf8_seq: s_idx = result.states[s_idx].target_map.get_resulting_target_state_index(byte) # All acceptance flags must belong to the original state machine for cmd in result.states[s_idx].single_entry: if cmd.__class__ != SeAccept: continue # HERE: As soon as something is wrong --> fire an exception assert cmd.acceptance_id() == self.id print " (OK=%i)" % self.id
class X: def __init__(self, Name): sh = StringIO("[:\\P{Script=%s}:]" % Name) self.name = Name self.charset = regex.snap_set_expression(sh, {}) self.sm = StateMachine() self.sm.add_transition(self.sm.init_state_index, self.charset, AcceptanceF=True) self.id = self.sm.get_id() def check(self, SM): """This function throws an exception as soon as one single value is not matched according to the expectation. """ print "Name = " + self.name, for interval in self.charset.get_intervals(PromiseToTreatWellF=True): for i in range(interval.begin, interval.end): utf8_seq = unicode_to_utf8(i) # Apply sequence to state machine s_idx = result.init_state_index for byte in utf8_seq: s_idx = result.states[ s_idx].target_map.get_resulting_target_state_index( byte) # All acceptance flags must belong to the original state machine for cmd in result.states[s_idx].single_entry: if cmd.__class__ != SeAccept: continue # HERE: As soon as something is wrong --> fire an exception assert cmd.acceptance_id() == self.id print " (OK=%i)" % self.id
class X: def __init__(self, Name): sh = StringIO("[:\\P{Script=%s}:]" % Name) self.name = Name self.charset = regex.snap_set_expression(sh, {}) self.sm = StateMachine() self.sm.add_transition(self.sm.init_state_index, self.charset, AcceptanceF=True) self.id = self.sm.get_id() def check(self, SM, TransformFunc): """This function throws an exception as soon as one single value is not matched according to the expectation. """ print "## [%i] Name = %s" % (self.id, self.name), interval_list = self.charset.get_intervals(PromiseToTreatWellF=True) interval_count = len(interval_list) for interval in interval_list: for i in range(interval.begin, interval.end): lexatom_seq = TransformFunc(i) # Apply sequence to state machine state = SM.apply_sequence(lexatom_seq) if state is None: error(self.sm, SM, lexatom_seq) # All acceptance flags must belong to the original state machine acceptance_id_list = [ cmd.acceptance_id() for cmd in state.single_entry.get_iterable(SeAccept) ] if acceptance_id_list and self.id not in acceptance_id_list: print eval("u'\U%08X'" % i) print "#Seq: ", ["%02X" % x for x in lexatom_seq] print "#acceptance-ids:", acceptance_id_list error(self.sm, SM, lexatom_seq) print " (OK=%i)" % interval_count
class X: def __init__(self, Name): sh = StringIO("[:\\P{Script=%s}:]" % Name) self.name = Name self.charset = regex.snap_set_expression(sh, {}) self.sm = StateMachine() self.sm.add_transition(self.sm.init_state_index, self.charset, AcceptanceF=True) self.id = self.sm.get_id() def check(self, SM): """This function throws an exception as soon as one single value is not matched according to the expectation. """ print "Name = " + self.name, for interval in self.charset.get_intervals(PromiseToTreatWellF=True): for i in range(interval.begin, interval.end): utf16_seq = unicode_to_utf16(i) # Apply sequence to state machine s_idx = result.init_state_index for word in utf16_seq: s_idx = result.states[ s_idx].target_map.get_resulting_target_state_index( word) assert s_idx is not None, \ "No acceptance for %X in [%X,%X] --> %s" % \ (i, interval.begin, interval.end - 1, repr(map(lambda x: "%04X." % x, utf16_seq))) # All acceptance flags must belong to the original state machine for cmd in result.states[s_idx].single_entry.get_iterable( SeAccept): # HERE: As soon as something is wrong --> fire an exception assert cmd.acceptance_id() == self.id print " (OK=%i)" % self.id