diff --git a/osh/split.py b/osh/split.py index 72514befb7..9296c820cf 100644 --- a/osh/split.py +++ b/osh/split.py @@ -183,6 +183,10 @@ def SplitForWordEval(self, s, ifs=None): """ sp = self._GetSplitter(ifs=ifs) spans = sp.Split(s, True) + + # Note: pass allow_escape=False so \ isn't special + #spans = sp.Split(s, False) + if 0: for span in spans: log('SPAN %s', span) @@ -221,6 +225,11 @@ def __init__(self, ifs_whitespace, ifs_other): self.ifs_whitespace = ifs_whitespace self.ifs_other = ifs_other + def __repr__(self): + # type: () -> str + return '' % (self.ifs_whitespace, + self.ifs_other) + def Split(self, s, allow_escape): # type: (str, bool) -> List[Span] """ diff --git a/osh/split_test.py b/osh/split_test.py index 621ba640fc..4aa7f6d1d7 100755 --- a/osh/split_test.py +++ b/osh/split_test.py @@ -5,6 +5,8 @@ import unittest +from core import state +from core import test_lib from osh import split # module under test @@ -160,5 +162,21 @@ def testTwoOther(self): _RunSplitCases(self, sp, CASES) +class SplitContextTest(unittest.TestCase): + + def testSplitForWordEval(self): + arena = test_lib.MakeArena('') + mem = state.Mem('', [], arena, [], {}) + # This is the default + #state.SetGlobalString(mem, 'IFS', split.DEFAULT_IFS) + + splitter = split.SplitContext(mem) + + # Can pass allow_escape=False + for s in ['', ' foo bar ', '\\']: + result = splitter.SplitForWordEval(s) + print(result) + + if __name__ == '__main__': unittest.main()