|
| 1 | +# Copyright 2022 The go-python Authors. All rights reserved. |
| 2 | +# Use of this source code is governed by a BSD-style |
| 3 | +# license that can be found in the LICENSE file. |
| 4 | + |
| 5 | +import glob |
| 6 | + |
| 7 | +def norm(vs): |
| 8 | + if len(vs) == 0: |
| 9 | + return vs |
| 10 | + if type(vs[0]) == type(""): |
| 11 | + return normStr(vs) |
| 12 | + return normBytes(vs) |
| 13 | + |
| 14 | +def normStr(vs): |
| 15 | + from os import sep |
| 16 | + x = [] |
| 17 | + for v in vs: |
| 18 | + x.append(v.replace('/', sep)) |
| 19 | + return x |
| 20 | + |
| 21 | +def normBytes(vs): |
| 22 | + from os import sep |
| 23 | + x = [] |
| 24 | + for v in vs: |
| 25 | + x.append(v.replace(b'/', bytes(sep, encoding="utf-8"))) |
| 26 | + return x |
| 27 | + |
| 28 | +def assertEqual(x, y): |
| 29 | + xx = norm(x) |
| 30 | + yy = norm(y) |
| 31 | + assert xx == yy, "got: %s, want: %s" % (repr(x), repr(y)) |
| 32 | + |
| 33 | + |
| 34 | +## test strings |
| 35 | +assertEqual(glob.glob('*'), ["glob.go", "glob_test.go", "testdata"]) |
| 36 | +assertEqual(glob.glob('*test*'), ["glob_test.go", "testdata"]) |
| 37 | +assertEqual(glob.glob('*/test*'), ["testdata/test.py", "testdata/test_golden.txt"]) |
| 38 | +assertEqual(glob.glob('*/test*_*'), ["testdata/test_golden.txt"]) |
| 39 | +assertEqual(glob.glob('*/t??t*_*'), ["testdata/test_golden.txt"]) |
| 40 | +assertEqual(glob.glob('*/t[e]?t*_*'), ["testdata/test_golden.txt"]) |
| 41 | +assertEqual(glob.glob('*/t[oe]?t*_*'), ["testdata/test_golden.txt"]) |
| 42 | +assertEqual(glob.glob('*/t[o]?t*_*'), []) |
| 43 | + |
| 44 | +## FIXME(sbinet) |
| 45 | +## assertEqual(glob.glob('*/t[!o]?t*_*'), ["testdata/test_golden.txt"]) |
| 46 | + |
| 47 | +## test bytes |
| 48 | +assertEqual(glob.glob(b'*'), [b"glob.go", b"glob_test.go", b"testdata"]) |
| 49 | +assertEqual(glob.glob(b'*test*'), [b"glob_test.go", b"testdata"]) |
| 50 | +assertEqual(glob.glob(b'*/test*'), [b"testdata/test.py", b"testdata/test_golden.txt"]) |
| 51 | +assertEqual(glob.glob(b'*/test*_*'), [b"testdata/test_golden.txt"]) |
| 52 | +assertEqual(glob.glob(b'*/t??t*_*'), [b"testdata/test_golden.txt"]) |
| 53 | +assertEqual(glob.glob(b'*/t[e]?t*_*'), [b"testdata/test_golden.txt"]) |
| 54 | +assertEqual(glob.glob(b'*/t[oe]?t*_*'), [b"testdata/test_golden.txt"]) |
| 55 | +assertEqual(glob.glob(b'*/t[o]?t*_*'), []) |
| 56 | + |
| 57 | +## FIXME(sbinet) |
| 58 | +## assertEqual(glob.glob(b'*/t[!o]?t*_*'), [b"testdata/test_golden.txt"]) |
0 commit comments