OILS / pyext / fastfunc_test.py View on Github | oilshell.org

55 lines, 33 significant
1#!/usr/bin/env python2
2from __future__ import print_function
3"""
4fastfunc_test.py: Tests for fastfunc.c
5"""
6import unittest
7
8from mycpp.mylib import log
9
10import fastfunc # module under test
11
12
13class FastfuncTest(unittest.TestCase):
14
15 def testJ8Encode(self):
16 s = 'hello \xff \x01 ' + u'\u03bc " \''.encode('utf-8')
17 #print(s)
18
19 x = fastfunc.J8EncodeString(s, 0)
20 print(x)
21
22 x = fastfunc.J8EncodeString(s, 1)
23 print(x)
24
25 def testShellEncode(self):
26 s = 'hello \xff \x01 ' + u'\u03bc " \''.encode('utf-8')
27 #print(s)
28
29 x = fastfunc.ShellEncodeString(s, 0)
30 print(x)
31
32 x = fastfunc.ShellEncodeString(s, 1)
33 print(x)
34
35 def testUtf8(self):
36 s = 'hi \xff'
37 self.assertEqual(True, fastfunc.PartIsUtf8(s, 0, 3))
38 self.assertEqual(False, fastfunc.PartIsUtf8(s, 3, 4))
39
40 def testCanOmit(self):
41 self.assertEqual(True, fastfunc.CanOmitQuotes('foo'))
42 self.assertEqual(False, fastfunc.CanOmitQuotes('foo bar'))
43 self.assertEqual(True, fastfunc.CanOmitQuotes('my-dir/my_file.cc'))
44 self.assertEqual(False, fastfunc.CanOmitQuotes(''))
45
46 self.assertEqual(False, fastfunc.CanOmitQuotes('true'))
47 self.assertEqual(False, fastfunc.CanOmitQuotes('false'))
48 self.assertEqual(False, fastfunc.CanOmitQuotes('null'))
49
50 self.assertEqual(True, fastfunc.CanOmitQuotes('truez'))
51 self.assertEqual(True, fastfunc.CanOmitQuotes('nul'))
52
53
54if __name__ == '__main__':
55 unittest.main()