def testGetVar(self): mem = _InitMem() # readonly a=x mem.SetVar(runtime.LhsName('a'), runtime.Str('x'), (var_flags_e.ReadOnly, ), scope_e.Dynamic) val = mem.GetVar('a', scope_e.Dynamic) test_lib.AssertAsdlEqual(self, runtime.Str('x'), val) val = mem.GetVar('undef', scope_e.Dynamic) test_lib.AssertAsdlEqual(self, runtime.Undef(), val)
def testGetVar(self): mem = _InitMem() # readonly a=x mem.SetVar( lvalue.Named('a'), value.Str('x'), scope_e.Dynamic, flags=state.SetReadOnly) val = mem.GetVar('a', scope_e.Dynamic) test_lib.AssertAsdlEqual(self, value.Str('x'), val) val = mem.GetVar('undef', scope_e.Dynamic) test_lib.AssertAsdlEqual(self, value.Undef(), val)
def testHereDoc(self): w_parser = test_lib.InitWordParser("""\ ls foo # Multiple newlines and comments should be ignored ls bar """) print('--MULTI') w = w_parser.ReadWord(lex_mode_e.ShCommand) parts = [Tok(Id.Lit_Chars, 'ls')] test_lib.AssertAsdlEqual(self, compound_word(parts), w) w = w_parser.ReadWord(lex_mode_e.ShCommand) parts = [Tok(Id.Lit_Chars, 'foo')] test_lib.AssertAsdlEqual(self, compound_word(parts), w) w = w_parser.ReadWord(lex_mode_e.ShCommand) t = Tok(Id.Op_Newline, None) test_lib.AssertAsdlEqual(self, t, w) w = w_parser.ReadWord(lex_mode_e.ShCommand) parts = [Tok(Id.Lit_Chars, 'ls')] test_lib.AssertAsdlEqual(self, compound_word(parts), w) w = w_parser.ReadWord(lex_mode_e.ShCommand) parts = [Tok(Id.Lit_Chars, 'bar')] test_lib.AssertAsdlEqual(self, compound_word(parts), w) w = w_parser.ReadWord(lex_mode_e.ShCommand) t = Tok(Id.Op_Newline, None) test_lib.AssertAsdlEqual(self, t, w) w = w_parser.ReadWord(lex_mode_e.ShCommand) t = Tok(Id.Eof_Real, '') test_lib.AssertAsdlEqual(self, t, w)
def testMultiLine(self): w_parser = InitWordParser("""\ ls foo # Multiple newlines and comments should be ignored ls bar """) print('--MULTI') w = w_parser.ReadWord(lex_mode_e.OUTER) parts = [ast.LiteralPart(ast.token(Id.Lit_Chars, 'ls'))] test_lib.AssertAsdlEqual(self, ast.CompoundWord(parts), w) w = w_parser.ReadWord(lex_mode_e.OUTER) parts = [ast.LiteralPart(ast.token(Id.Lit_Chars, 'foo'))] test_lib.AssertAsdlEqual(self, ast.CompoundWord(parts), w) w = w_parser.ReadWord(lex_mode_e.OUTER) t = ast.token(Id.Op_Newline, '\n') test_lib.AssertAsdlEqual(self, ast.TokenWord(t), w) w = w_parser.ReadWord(lex_mode_e.OUTER) parts = [ast.LiteralPart(ast.token(Id.Lit_Chars, 'ls'))] test_lib.AssertAsdlEqual(self, ast.CompoundWord(parts), w) w = w_parser.ReadWord(lex_mode_e.OUTER) parts = [ast.LiteralPart(ast.token(Id.Lit_Chars, 'bar'))] test_lib.AssertAsdlEqual(self, ast.CompoundWord(parts), w) w = w_parser.ReadWord(lex_mode_e.OUTER) t = ast.token(Id.Op_Newline, '\n') test_lib.AssertAsdlEqual(self, ast.TokenWord(t), w) w = w_parser.ReadWord(lex_mode_e.OUTER) t = ast.token(Id.Eof_Real, '') test_lib.AssertAsdlEqual(self, ast.TokenWord(t), w)