Пример #1
0
 def test_parse_cmd_options_2(self):
     """test if parser parse success"""
     source = "play 晴天 [artist=周杰伦] "
     parser = Parser(source)
     request = parser.parse()
     self.assertEqual(request.cmd, 'play')
     self.assertEqual(request.cmd_args, ['晴天'])
     self.assertEqual(request.cmd_options, {'artist': '周杰伦'})
Пример #2
0
 def to_cmd(self):
     if self.options_str:
         options = Parser(self.options_str).parse_cmd_options()
     else:
         options = {}
     return Cmd(self.cmd, *self.args, options=options)
Пример #3
0
 def test_parse_heredoc(self):
     source = "play << EOF"
     req = Parser(source).parse()
     self.assertEqual(req.has_heredoc, True)
     self.assertEqual(req.heredoc_word, 'EOF')
Пример #4
0
 def test_token_after_req(self):
     source = "play #: miao miao"
     with self.assertRaises(FuoSyntaxError):
         Parser(source).parse()
Пример #5
0
 def test_read_cmd_error(self):
     text = "'hello world'"
     with self.assertRaises(FuoSyntaxError):
         Parser(text).parse()
Пример #6
0
 def test_parse_req_options_2(self):
     """test if ok when there is empty req option """
     source = "play #:"
     req = Parser(source).parse()
     self.assertEqual(req.options, {})
Пример #7
0
 def test_parse_req_options(self):
     source = "play hay [artist='miao'] #: json"
     req = Parser(source).parse()
     self.assertEqual(req.options, {'json': True})
Пример #8
0
 def test_parse_value_false_to_False(self):
     source = "p [a=false] "
     req = Parser(source).parse()
     self.assertEqual(req.cmd_options, {'a': False})
Пример #9
0
 def test_parse_value_true_to_True(self):
     source = "p [a=true] "
     req = Parser(source).parse()
     self.assertEqual(req.cmd_options, {'a': True})
Пример #10
0
 def test_parse_cmd_options_4(self):
     """test if ok when there is no cmd option"""
     source = 'p [a,b=c]'
     req = Parser(source).parse()
     self.assertEqual(req.cmd, 'p')
     self.assertEqual(req.cmd_options, {'a': True, 'b': 'c'})
Пример #11
0
 def test_parse_cmd_options_3(self):
     """test if ok when there is no cmd option"""
     req = Parser('p []').parse()
     self.assertEqual(req.cmd, 'p')
     self.assertEqual(req.cmd_options, {})
Пример #12
0
 def test_parse_cmd_options_1(self):
     """test if parser can find error in option expr"""
     source = "status [artist=]"
     parser = Parser(source)
     with self.assertRaises(FuoSyntaxError):
         parser.parse()
Пример #13
0
 def test_parse_cmd_unquote_string(self):
     source = "play 晴天"
     parser = Parser(source)
     request = parser.parse()
     self.assertEqual(request.cmd, 'play')
     self.assertEqual(request.cmd_args, ['晴天'])
Пример #14
0
 def test_parse_cmd_furi(self):
     source = "play fuo://local/songs/1"
     parser = Parser(source)
     request = parser.parse()
     self.assertEqual(request.cmd, 'play')
     self.assertEqual(request.cmd_args, ['fuo://local/songs/1'])
Пример #15
0
 def test_no_token(self):
     with self.assertRaises(FuoSyntaxError):
         Parser('').parse()