from nose.tools import *
from whitepy.lexerconstants import *
import unittest
import whitepy.lexer as lexer


class TestLexer(unittest.TestCase):

    def _get_lexer(self, line):
        return lexer.Lexer(line=line)

    def _sample_ws(self, ws_type):
        ws_samples = {
            'valid': "   \t\n",
            'invalid_int': "   \t"
        }
        return self._get_lexer(ws_samples[ws_type])

    def test_get_int(self):
        lexer = self._sample_ws('valid')
        r = lexer._get_int()
        assert r.get_type() == 'INT' and r.get_value() == 'POSITIVE 001'

    @raises(lexer.IntError)
    def test_invalid_int(self):
        lexer = self._sample_ws('invalid_int')
        lexer._get_int()

    def test_get_token(self):
        lexer = self._sample_ws('valid')
        lexer.pos = 1
        r = lexer._get_token(IMP_CONST)
        assert r.get_type() == 'STACK_MANIPULATION'

    def test_get_all_tokens(self):
        lexer = self._sample_ws('valid')
        lexer.get_all_tokens()
        t = lexer.tokens
        assert t[0].get_type() is 'STACK_MANIPULATION' and \
            t[1].get_type() is 'PUSH' and t[2].get_type() is 'INT'

@@ -335,16 +335,52 @@
  %22   %5Ct%22
+,%0A            'non_ws': %22A   %5CtB%5CnC%22
 %0A       
@@ -1186,8 +1186,282 @@
 s 'INT'%0A
+%0A    def test_get_all_tokens_with_non_ws(self):%0A        lexer = self._sample_ws('non_ws')%0A        lexer.get_all_tokens()%0A        t = lexer.tokens%0A        assert t%5B0%5D.get_type() is 'STACK_MANIPULATION' and %5C%0A            t%5B1%5D.get_type() is 'PUSH' and t%5B2%5D.get_type() is 'INT'%0A

Add test to check non ws characters