Skip to content

Commit 70f81fc

Browse files
authored
Merge pull request #4 from alingse/add-test
添加 escape 的测试
2 parents 50d5464 + c7138bd commit 70f81fc

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

tests/test_escape.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# coding=utf-8
2+
# author@alingse
3+
# 2016.11.21
4+
5+
import unittest
6+
7+
from jsoncsv.utils import encode_safe_key, decode_safe_key
8+
9+
10+
class Testescape(unittest.TestCase):
11+
12+
def test_all(self):
13+
path = ['A', 'B', '..', '\.\\ww']
14+
15+
for sep in 'AB.w':
16+
key = encode_safe_key(path, sep)
17+
_path = decode_safe_key(key, sep)
18+
19+
self.assertListEqual(path, _path)
20+
21+
def test_encode(self):
22+
path = ['A', 'B', 'C', 'www.xxx.com']
23+
sep = '.'
24+
key = encode_safe_key(path, sep)
25+
26+
self.assertEqual(key, 'A\.B\.C\.www.xxx.com')
27+
28+
def test_decode(self):
29+
key = 'A\.B\.C\.www.xxx.com'
30+
sep = '.'
31+
path = decode_safe_key(key, sep)
32+
33+
self.assertEqual(path[0], 'A')
34+
self.assertEqual(path[1], 'B')
35+
self.assertEqual(path[2], 'C')
36+
self.assertEqual(path[3], 'www.xxx.com')

0 commit comments

Comments
 (0)