Example #1
0
  def test_extra_get_tok_1(self):
    '''
    test to make sure we handle extra calls to get_tok gracefully
    '''
    scanner_1 = lex.Scanner(self.sim.new_var('test_1'))
    scanner_2 = lex.Scanner(self.sim.new_var('test_2', ''))
    scanner_3 = lex.Scanner(self.sim.new_var('test_3', None))

    for i in range(0,10):
      # should return an empty list and not throw an error
      self.assert_(scanner_1.get_tok() is None)
      self.assert_(scanner_2.get_tok() is None)
      self.assert_(scanner_3.get_tok() is None)
Example #2
0
  def test_empty_eqn(self):
    '''
    test to make sure we handle empty equations
    '''
    scanner_1 = lex.Scanner(self.sim.new_var('test_1'))
    scanner_2 = lex.Scanner(self.sim.new_var('test_2', ''))
    scanner_3 = lex.Scanner(self.sim.new_var('test_3', None))
    scanner_4 = lex.Scanner(self.sim.new_var('test_4', '       '))

    # should return none, since we have only whitespace
    self.assert_(scanner_1.get_tok() is None)
    self.assert_(scanner_2.get_tok() is None)
    self.assert_(scanner_3.get_tok() is None)
    self.assert_(scanner_4.get_tok() is None)
Example #3
0
 def test_only_tokens_1(self):
   '''
   Test to make sure we only return Tokens.
   '''
   var = self.sim.new_var('test', self.eqn5)
   scanner = lex.Scanner(var)
   tok = scanner.get_tok()
   while tok is not None:
     self.assert_(isinstance(tok, lex.Token))
     tok = scanner.get_tok()
Example #4
0
 def test_number_value(self):
   '''
   test to make sure we handle numbers with leading decimal points
   '''
   var = self.sim.new_var('test', self.eqn_dec)
   scanner = lex.Scanner(var)
   num_toks = 0
   tok = scanner.get_tok()
   while tok is not None:
     self.assert_(tok.iden == self.eqn_dec, 
                  '%s should equal %s' % (tok.iden, self.eqn_dec))
     num_toks += 1
     tok = scanner.get_tok()
Example #5
0
  def test_ok_eqn(self):
    '''
    test to make sure we handle good equations
    '''
    var = self.sim.new_var('test', self.eqn_ok)
    scanner = lex.Scanner(var)
    num_toks = 0
    tok = scanner.get_tok()
    while tok is not None:
      self.assert_(isinstance(tok, lex.Token))
      num_toks += 1
      tok = scanner.get_tok()

    self.assert_(num_toks == 3)
Example #6
0
  def test_leading_decimal(self):
    '''
    test to make sure we handle numbers with leading decimal points
    '''
    var = self.sim.new_var('test', self.eqn_dec)
    scanner = lex.Scanner(var)
    num_toks = 0
    tok = scanner.get_tok()
    while tok is not None:
      self.assert_(tok.kind is lex.NUMBER)
      num_toks += 1
      tok = scanner.get_tok()

    self.assert_(num_toks == 1)
Example #7
0
 def test_tok_contents(self):
   '''
   test to make sure we pass along the contents of the tokens correctly
   '''
   var = self.sim.new_var('test', self.eqn_space)
   scanner = lex.Scanner(var)
   i = 0
   tok = scanner.get_tok()
   while tok is not None:
     self.assert_(tok.iden == self.tok_idens[i],
                  '%s (%s) should be %s (%s)' % (tok.iden,
                    type(tok.iden), self.tok_idens[i],
                    type(self.tok_idens[i])))
     i += 1
     tok = scanner.get_tok()
Example #8
0
  def test_leading_and_trailing_spaces(self):
    '''
    Test to make sure we handle integral equations with l and r spaces.
    '''
    var = self.sim.new_var('test', self.eqn5)
    scanner = lex.Scanner(var)
    toks = []
    tok = scanner.get_tok()
    while tok is not None:
      toks.append(tok)
      tok = scanner.get_tok()
    num_toks = len(toks)
    first_tok = toks[0]

    self.assert_(num_toks is self.num_toks,
                 'expected %d toks, got %d : %s' %
                 (self.num_toks, num_toks, toks))
    self.assert_(first_tok.kind is lex.INTEGRAL,
                 'integral not promoted: \'%s\' is %s' %
                 (first_tok.iden, lex.name_for_tok_type(first_tok.kind)))