Skip to content

Commit

Permalink
Merge branch 'master' into word-splitting
Browse files Browse the repository at this point in the history
  • Loading branch information
PossiblyAShrub committed Nov 27, 2024
2 parents d54dcb6 + f34b966 commit 57cbcca
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
9 changes: 9 additions & 0 deletions osh/split.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 '<IfsSplitter whitespace=%r other=%r>' % (self.ifs_whitespace,
self.ifs_other)

def Split(self, s, allow_escape):
# type: (str, bool) -> List[Span]
"""
Expand Down
18 changes: 18 additions & 0 deletions osh/split_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

import unittest

from core import state
from core import test_lib
from osh import split # module under test


Expand Down Expand Up @@ -160,5 +162,21 @@ def testTwoOther(self):
_RunSplitCases(self, sp, CASES)


class SplitContextTest(unittest.TestCase):

def testSplitForWordEval(self):
arena = test_lib.MakeArena('<SplitContextTest>')
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()

0 comments on commit 57cbcca

Please sign in to comment.