aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/test/skylark/testdata
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/skylark/testdata')
-rw-r--r--src/test/skylark/testdata/all_any.sky46
-rw-r--r--src/test/skylark/testdata/string_partition.sky40
-rw-r--r--src/test/skylark/testdata/string_split.sky45
-rw-r--r--src/test/skylark/testdata/string_splitlines.sky29
-rw-r--r--src/test/skylark/testdata/string_test_characters.sky54
5 files changed, 214 insertions, 0 deletions
diff --git a/src/test/skylark/testdata/all_any.sky b/src/test/skylark/testdata/all_any.sky
new file mode 100644
index 0000000000..1b37967737
--- /dev/null
+++ b/src/test/skylark/testdata/all_any.sky
@@ -0,0 +1,46 @@
+# All with empty value
+assert_eq(all(''), True)
+assert_eq(all([]), True)
+
+# All with list
+assert_eq(all('test'), True)
+assert_eq(all([False]), False)
+assert_eq(all([True, False]), False)
+assert_eq(all([False, False]), False)
+assert_eq(all([False, True]), False)
+assert_eq(all(['', True]), False)
+assert_eq(all([0, True]), False)
+assert_eq(all([[], True]), False)
+assert_eq(all([True, 't', 1]), True)
+
+# All with dict
+assert_eq(all({1 : None}), True)
+assert_eq(all({None : 1}), False)
+
+# Any with empty value
+assert_eq(any(''), False)
+assert_eq(any([]), False)
+
+# Any with list
+assert_eq(any('test'), True)
+assert_eq(any([False]), False)
+assert_eq(any([0]), False)
+assert_eq(any(['']), False)
+assert_eq(any([[]]), False)
+assert_eq(any([True, False]), True)
+assert_eq(any([False, False]), False)
+assert_eq(any([False, '', 0]), False)
+assert_eq(any([False, '', 42]), True)
+
+# Any with dict
+assert_eq(any({1 : None, '' : None}), True)
+assert_eq(any({None : 1, '' : 2}), False)
+
+---
+all(None) ### type 'NoneType' is not iterable
+---
+any(None) ### type 'NoneType' is not iterable
+---
+any(1) ### type 'int' is not iterable
+---
+all(1) ### type 'int' is not iterable
diff --git a/src/test/skylark/testdata/string_partition.sky b/src/test/skylark/testdata/string_partition.sky
new file mode 100644
index 0000000000..dc2d5be942
--- /dev/null
+++ b/src/test/skylark/testdata/string_partition.sky
@@ -0,0 +1,40 @@
+assert_eq('lawl'.partition('a'), ('l', 'a', 'wl'))
+assert_eq('lawl'.rpartition('a'), ('l', 'a', 'wl'))
+assert_eq('google'.partition('o'), ('g', 'o', 'ogle'))
+assert_eq('google'.rpartition('o'), ('go', 'o', 'gle'))
+assert_eq('xxx'.partition('x'), ('', 'x', 'xx'))
+assert_eq('xxx'.rpartition('x'), ('xx', 'x', ''))
+assert_eq(''.partition('a'), ('', '', ''))
+assert_eq(''.rpartition('a'), ('', '', ''))
+
+# default separator
+assert_eq('hi this is a test'.partition(), ('hi', ' ', 'this is a test'))
+assert_eq('hi this is a test'.rpartition(), ('hi this is a', ' ', 'test'))
+assert_eq('google'.partition(), ('google', '', ''))
+assert_eq('google'.rpartition(), ('', '', 'google'))
+
+# no match
+assert_eq('google'.partition('x'), ('google', '', ''))
+assert_eq('google'.rpartition('x'), ('', '', 'google'))
+
+# at word boundaries
+assert_eq('goog'.partition('g'), ('', 'g', 'oog'))
+assert_eq('goog'.rpartition('g'), ('goo', 'g', ''))
+assert_eq('plex'.partition('p'), ('', 'p', 'lex'))
+assert_eq('plex'.rpartition('p'), ('', 'p', 'lex'))
+assert_eq('plex'.partition('x'), ('ple', 'x', ''))
+assert_eq('plex'.rpartition('x'), ('ple', 'x', ''))
+
+assert_eq('google'.partition('oog'), ('g', 'oog', 'le'))
+assert_eq('google'.rpartition('oog'), ('g', 'oog', 'le'))
+assert_eq('lolgooglolgooglolgooglol'.partition('goog'), ('lol', 'goog', 'lolgooglolgooglol'))
+assert_eq('lolgooglolgooglolgooglol'.rpartition('goog'), ('lolgooglolgooglol', 'goog', 'lol'))
+
+# full string
+assert_eq('google'.partition('google'), ('', 'google', ''))
+assert_eq('google'.rpartition('google'), ('', 'google', ''))
+
+---
+'google'.partition('') ### Empty separator
+---
+'google'.rpartition('') ### Empty separator
diff --git a/src/test/skylark/testdata/string_split.sky b/src/test/skylark/testdata/string_split.sky
new file mode 100644
index 0000000000..e8c5ba1022
--- /dev/null
+++ b/src/test/skylark/testdata/string_split.sky
@@ -0,0 +1,45 @@
+# split
+assert_eq('h i'.split(' '), ['h', 'i'])
+assert_eq('h i p'.split(' '), ['h', 'i', 'p'])
+assert_eq('a,e,i,o,u'.split(',', 2), ['a', 'e', 'i,o,u'])
+assert_eq(' 1 2 3 '.split(' '), ['', '', '1', '', '2', '', '3', '', ''])
+
+# rsplit
+assert_eq('abcdabef'.rsplit('ab'), ['', 'cd', 'ef'])
+assert_eq('google_or_gogol'.rsplit('go'), ['', 'ogle_or_', '', 'l'])
+
+# rsplit regex
+assert_eq('foo/bar.lisp'.rsplit('.'), ['foo/bar', 'lisp'])
+assert_eq('foo/bar.?lisp'.rsplit('.?'), ['foo/bar', 'lisp'])
+assert_eq('fwe$foo'.rsplit('$'), ['fwe', 'foo'])
+assert_eq('windows'.rsplit('\w'), ['windows'])
+
+# rsplit no match
+assert_eq(''.rsplit('o'), [''])
+assert_eq('google'.rsplit('x'), ['google'])
+
+# rsplit separator
+assert_eq('xxxxxx'.rsplit('x'), ['', '', '', '', '', '', ''])
+assert_eq('xxxxxx'.rsplit('x', 1), ['xxxxx', ''])
+assert_eq('xxxxxx'.rsplit('x', 2), ['xxxx', '', ''])
+assert_eq('xxxxxx'.rsplit('x', 3), ['xxx', '', '', ''])
+assert_eq('xxxxxx'.rsplit('x', 4), ['xx', '', '', '', ''])
+assert_eq('xxxxxx'.rsplit('x', 5), ['x', '', '', '', '', ''])
+assert_eq('xxxxxx'.rsplit('x', 6), ['', '', '', '', '', '', ''])
+assert_eq('xxxxxx'.rsplit('x', 7), ['', '', '', '', '', '', ''])
+
+# split max split
+assert_eq('google'.rsplit('o'), ['g', '', 'gle'])
+assert_eq('google'.rsplit('o'), ['g', '', 'gle'])
+assert_eq('google'.rsplit('o', 1), ['go', 'gle'])
+assert_eq('google'.rsplit('o', 2), ['g', '', 'gle'])
+assert_eq('google'.rsplit('o', 3), ['g', '', 'gle'])
+assert_eq('ogooglo'.rsplit('o'), ['', 'g', '', 'gl', ''])
+assert_eq('ogooglo'.rsplit('o', 1), ['ogoogl', ''])
+assert_eq('ogooglo'.rsplit('o', 2), ['ogo', 'gl', ''])
+assert_eq('ogooglo'.rsplit('o', 3), ['og', '', 'gl', ''])
+assert_eq('ogooglo'.rsplit('o', 4), ['', 'g', '', 'gl', ''])
+assert_eq('ogooglo'.rsplit('o', 5), ['', 'g', '', 'gl', ''])
+assert_eq('google'.rsplit('google'), ['', ''])
+assert_eq('google'.rsplit('google', 1), ['', ''])
+assert_eq('google'.rsplit('google', 2), ['', ''])
diff --git a/src/test/skylark/testdata/string_splitlines.sky b/src/test/skylark/testdata/string_splitlines.sky
new file mode 100644
index 0000000000..8590513f3a
--- /dev/null
+++ b/src/test/skylark/testdata/string_splitlines.sky
@@ -0,0 +1,29 @@
+# Empty line
+assert_eq(''.splitlines(), [])
+assert_eq('\n'.splitlines(), [''])
+
+# Starts with line break
+assert_eq('\ntest'.splitlines(), ['', 'test'])
+
+# Ends with line break
+assert_eq('test\n'.splitlines(), ['test'])
+
+# Different line breaks
+assert_eq('this\nis\na\ntest'.splitlines(), ['this', 'is', 'a', 'test'])
+
+# Only line breaks
+assert_eq('\n\n\n'.splitlines(), ['', '', ''])
+assert_eq('\r\r\r'.splitlines(), ['', '', ''])
+assert_eq('\n\r\n\r'.splitlines(), ['', '', ''])
+assert_eq('\r\n\r\n\r\n'.splitlines(), ['', '', ''])
+
+# Escaped sequences
+assert_eq('\n\\n\\\n'.splitlines(), ['', '\\n\\'])
+
+# KeepEnds
+assert_eq(''.splitlines(True), [])
+assert_eq('\n'.splitlines(True), ['\n'])
+assert_eq('this\nis\r\na\rtest'.splitlines(True), ['this\n', 'is\r\n', 'a\r', 'test'])
+assert_eq('\ntest'.splitlines(True), ['\n', 'test'])
+assert_eq('test\n'.splitlines(True), ['test\n'])
+assert_eq('\n\\n\\\n'.splitlines(True), ['\n', '\\n\\\n'])
diff --git a/src/test/skylark/testdata/string_test_characters.sky b/src/test/skylark/testdata/string_test_characters.sky
new file mode 100644
index 0000000000..df81d37573
--- /dev/null
+++ b/src/test/skylark/testdata/string_test_characters.sky
@@ -0,0 +1,54 @@
+# isalnum
+assert_eq(''.isalnum(), False)
+assert_eq('a0 33'.isalnum(), False)
+assert_eq('1'.isalnum(), True)
+assert_eq('a033'.isalnum(), True)
+
+# isdigit
+assert_eq(''.isdigit(), False)
+assert_eq(' '.isdigit(), False)
+assert_eq('a'.isdigit(), False)
+assert_eq('0234325.33'.isdigit(), False)
+assert_eq('1'.isdigit(), True)
+assert_eq('033'.isdigit(), True)
+
+# isspace
+assert_eq(''.isspace(), False)
+assert_eq('a'.isspace(), False)
+assert_eq('1'.isspace(), False)
+assert_eq('\ta\n'.isspace(), False)
+assert_eq(' '.isspace(), True)
+assert_eq('\t\n'.isspace(), True)
+
+# islower
+assert_eq(''.islower(), False)
+assert_eq(' '.islower(), False)
+assert_eq('1'.islower(), False)
+assert_eq('Almost'.islower(), False)
+assert_eq('abc'.islower(), True)
+assert_eq(' \nabc'.islower(), True)
+assert_eq('abc def\n'.islower(), True)
+assert_eq('\ta\n'.islower(), True)
+
+# isupper
+assert_eq(''.isupper(), False)
+assert_eq(' '.isupper(), False)
+assert_eq('1'.isupper(), False)
+assert_eq('aLMOST'.isupper(), False)
+assert_eq('ABC'.isupper(), True)
+assert_eq(' \nABC'.isupper(), True)
+assert_eq('ABC DEF\n'.isupper(), True)
+assert_eq('\tA\n'.isupper(), True)
+
+# istitle
+assert_eq(''.istitle(), False)
+assert_eq(' '.istitle(), False)
+assert_eq('134'.istitle(), False)
+assert_eq('almost Correct'.istitle(), False)
+assert_eq('1nope Nope Nope'.istitle(), False)
+assert_eq('NO Way'.istitle(), False)
+assert_eq('T'.istitle(), True)
+assert_eq('Correct'.istitle(), True)
+assert_eq('Very Correct! Yes\nIndeed1X'.istitle(), True)
+assert_eq('1234Ab Ab'.istitle(), True)
+assert_eq('\tA\n'.istitle(), True)