Example #1
0
    def setUp(self):
        self.interp = CmdInterp()

        self.interp = CmdInterp()
        self.interp.add_lsa(
            LSAlias(lsa_multiply_spoken_forms, lsa_multiply_meanings))
        self.interp.add_lsa(LSAlias(lsa_not_spoken_forms, lsa_not_meanings))
Example #2
0
  def test_the_index_of_simple_csc_and_an_lsa_definition(self):
      wciSay = WhatCanISay.WhatCanISay()
      interp = CmdInterp()
      # do one csc and one lsa:
      interp.add_csc(
          CSCmd(["equals"],
                meanings={contAny: ActionInsert("====")},
                name="equals csc"))
      interp.add_lsa(
          LSAlias(["plus"],
                  meanings={all_languages: " + "},
                  name="plus sign"))
      wciSay.load_commands_from_interpreter(self._app(), interp, 'C')
      expected = \
 {'C': {'equals': [[{'action': "Inserts '====^' in current buffer",
                  'doc': None,
                  'equiv': 'Any',
                  'scope': 'global',
                  'setdescription': 'no description',
                  'setname': 'cscs'}]],
      'plus': [{'description': 'no description',
               'name': 'plus sign',
               'new_symbol': None,
               'setname': 'lsas',
               'spacing': 0,
               'written_form': ' + '}]}}
      self.assert_equal(
          expected, wciSay.index,
          "index of one CSC and one LSA command is not as expected")
Example #3
0
    def test_This_is_how_you_can_make_a_special_case_for_one_language(self):

        interp = CmdInterp()        
##        In next test all languages are first set to "ccc",
##        and then for python is changed to 'qqq'.
        interp.add_lsa(LSAlias(['spoken', 'form'],
                                    {'python': 'qqq', all_languages:  'ccc'}))
                                                         
        all_lsas = interp.language_specific_aliases
        python_lsas = all_lsas['python']
        # extract and check only one item:
        for an_LSA in python_lsas.items():
            wordList, entry = an_LSA
            spoken_form_text = ' '.join(wordList)
            written_form_text = getattr(entry, 'written_form', '')
            expected_spoken_form = 'spoken'
            expected_written_form = 'qqq'
            self.assert_equal(expected_spoken_form, spoken_form_text,
                               "LSA spoken form is not as expected")
            self.assert_equal(expected_written_form, written_form_text,
                               "LSA written form is not as expected")
            break
        c_lsas = all_lsas['C']
        # extract and check only one item:
        for an_LSA in c_lsas.items():
            wordList, entry = an_LSA
            spoken_form_text = ' '.join(wordList)
            written_form_text = getattr(entry, 'written_form', '')
            expected_spoken_form = 'spoken'
            expected_written_form = 'ccc'
            self.assert_equal(expected_spoken_form, spoken_form_text,
                               "LSA spoken form is not as expected")
            self.assert_equal(expected_written_form, written_form_text,
                               "LSA written form is not as expected")
            break
Example #4
0
    def test_This_is_how_you_create_a_LSAlias__instance(self):

        interp = CmdInterp()        

        interp.add_lsa(LSAlias(['spoken', 'form'],
                                    {'C':  'sss', 'python': 'ppp'}))
                                                         
        all_lsas = interp.language_specific_aliases
        languages = all_lsas.keys()
        languages.sort()
        expected = list(all_languages)  # list (of keys)
        self.assert_equal(expected, languages, "LSAs, all languages should have a key, this was not as expected")
        expected = all_languages  # tuple
        self.assert_equal(expected, interp.supported_languages(),
                          "LSAs, languages not as expected through interp method")
        python_lsas = all_lsas['python']
        # extract and check only one item:
        for an_LSA in python_lsas.items():
            wordList, entry = an_LSA
            spoken_form_text = ' '.join(wordList)
            written_form_text = getattr(entry, 'written_form', '')
            expected_spoken_form = 'spoken'
            expected_written_form = 'ppp'
            self.assert_equal(expected_spoken_form, spoken_form_text,
                               "LSA spoken form is not as expected")
            self.assert_equal(expected_written_form, written_form_text,
                               "LSA written form is not as expected")
            break
Example #5
0
    def test_This_is_how_you_can_make_a_special_case_c_style_languages(self):

        interp = CmdInterp()
        ##        In next test all languages are first set to "aaa",
        ##        next c_style_languages to ccc, and
        ##        after that java and python to something more specific
        ##        and then for python is changed to 'qqq'.
        interp.add_lsa(
            LSAlias(
                ['spoken', 'form'], {
                    'java': 'jjj',
                    'python': 'pppp',
                    all_languages: 'aaa',
                    c_style_languages: 'ccc'
                }))

        all_lsas = interp.language_specific_aliases
        python_lsas = all_lsas['python']
        # extract and check only one item:
        for an_LSA in python_lsas.items():
            wordList, entry = an_LSA
            spoken_form_text = ' '.join(wordList)
            written_form_text = getattr(entry, 'written_form', '')
            expected_spoken_form = 'spoken'
            expected_written_form = 'pppp'
            self.assert_equal(expected_spoken_form, spoken_form_text,
                              "LSA spoken form is not as expected")
            self.assert_equal(expected_written_form, written_form_text,
                              "LSA written form is not as expected")
            break
        c_lsas = all_lsas['C']
        # extract and check only one item:
        for an_LSA in c_lsas.items():
            wordList, entry = an_LSA
            spoken_form_text = ' '.join(wordList)
            written_form_text = getattr(entry, 'written_form', '')
            expected_spoken_form = 'spoken'
            expected_written_form = 'ccc'
            self.assert_equal(expected_spoken_form, spoken_form_text,
                              "LSA spoken form is not as expected")
            self.assert_equal(expected_written_form, written_form_text,
                              "LSA written form is not as expected")
            break

        java_lsas = all_lsas['java']
        # extract and check only one item:
        for an_LSA in java_lsas.items():
            wordList, entry = an_LSA
            spoken_form_text = ' '.join(wordList)
            written_form_text = getattr(entry, 'written_form', '')
            expected_spoken_form = 'spoken'
            expected_written_form = 'jjj'
            self.assert_equal(expected_spoken_form, spoken_form_text,
                              "LSA spoken form is not as expected")
            self.assert_equal(expected_written_form, written_form_text,
                              "LSA written form is not as expected")
            break
Example #6
0
 def test_This_is_how_you_create_a_WhatCanISay_instance(self):
     wciSay = WhatCanISay.WhatCanISay()
     interp = CmdInterp()
     # load one lsa and one csc:
     interp.add_csc(
         CSCmd(["equals"],
               meanings={contAny: ActionInsert("====")},
               name="equals csc"))
     interp.add_lsa(
         LSAlias(["plus"],
                 meanings={all_languages: " + "},
                 name="plus sign"))
     wciSay.load_commands_from_interpreter(self._app(), interp, 'C')
Example #7
0
    def test_the_index_of_a_cmdset_with_an_lsa_and_a_csc_in_it(self):
        wciSay = WhatCanISay.WhatCanISay()
        interp = CmdInterp()
        # the new CmdSet can contain both CSCs and LSAs...
        # do one csc and one lsa:
        cmds = CmdSet("commands set", description="generic commands set")
        cmds.add_lsa(
            LSAlias(["plus"],
                    meanings={all_languages: " + "},
                    name="plus sign"))
        # without docstring:
        cmds.add_csc(
            CSCmd(["equals"], meanings={contAny: ActionInsert("====")}))
        # with docstring:
        cmds.add_csc(
            CSCmd(["not equal"],
                  meanings={contAny: ActionInsert(" != ")},
                  docstring="csc not equal"))

        interp.add_cmd_set(cmds)
        wciSay.load_commands_from_interpreter(self._app(), interp, 'C')
        expected = \
   {'C': {'equals': [[{'action': "Inserts '====^' in current buffer",
                    'doc': None,
                    'equiv': 'Any',
                    'scope': 'global',
                    'setdescription': 'generic commands set',
                    'setname': 'commands set'}]],
        'not equal': [[{'action': "Inserts ' != ^' in current buffer",
                       'doc': 'csc not equal',
                       'equiv': 'Any',
                       'scope': 'global',
                       'setdescription': 'generic commands set',
                       'setname': 'commands set'}]],
        'plus': [{'name': 'plus sign',
                 'new_symbol': None,
                 'setdescription': 'generic commands set',
                 'setname': 'commands set',
                 'spacing': 0,
                 'written_form': ' + '}]}}
        self.assert_equal(
            expected, wciSay.index,
            "index of one CSC and one LSA command is not as expected")
Example #8
0
    def test_the_index_of_c_else_with_different_csc_set_name_as_python_else(
            self):
        wciSay = WhatCanISay.WhatCanISay()
        interp = CmdInterp()
        # do a csc set for python and a csc set for c
        # note: for try all went well in C, except for the setname
        cscs1 = CSCmdSet('try command python',
                         description='description of CSCS')
        cscs2 = CSCmdSet('try command C',
                         description='description duplicates of CSCS')
        cscs2.add_csc(
            CSCmd(spoken_forms=csc_else_spoken_forms,
                  meanings=csc_c_else_meanings,
                  docstring=csc_c_else_docstring))
        cscs1.add_csc(
            CSCmd(spoken_forms=csc_else_spoken_forms,
                  meanings=csc_python_else_meanings,
                  docstring=csc_python_else_docstring))
        interp.add_csc_set(cscs2)
        interp.add_csc_set(cscs1)
        interp.add_lsa(
            LSAlias(["plus"],
                    meanings={all_languages: " + "},
                    name="plus sign"))

        wciSay.load_commands_from_interpreter(self._app(), interp, 'C')
        expected = \
   {'C': {'else': [[{'action': 'else clause of a C conditional',
                  'doc': 'else clause only c',
                  'equiv': 'Language: C',
                  'scope': 'buffer',
                  'setdescription': 'description duplicates of CSCS',
                  'setname': 'try command C'}]],
        'plus': [{'description': 'no description',
                 'name': 'plus sign',
                 'new_symbol': None,
                 'setname': 'lsas',
                 'spacing': 0,
                 'written_form': ' + '}]}}
        self.assert_equal(
            expected, wciSay.index,
            "index of else csc set in C different from expected")

        wciSay.load_commands_from_interpreter(self._app(), interp, 'python')
        expected = \
   {'python': {'else': [[{'action': 'no docstring available',
                       'doc': 'else clause only python',
                       'equiv': 'BlankLine: python',
                       'scope': 'immediate',
                       'setdescription': 'description of CSCS',
                       'setname': 'try command python'},
                      {'action': "Inserts 'else on non blank line^' in current buffer",
                       'doc': 'else clause only python',
                       'equiv': 'Language: python',
                       'scope': 'buffer',
                       'setdescription': 'description of CSCS',
                       'setname': 'try command python'}]],
            'plus': [{'description': 'no description',
                      'name': 'plus sign',
                      'new_symbol': None,
                      'setname': 'lsas',
                      'spacing': 0,
                      'written_form': ' + '}]}}
        self.assert_equal(
            expected, wciSay.index,
            "index of else csc set in python different from expected")
Example #9
0
    def setUp(self):
        print '\n=======setting up WhatCanISay test instance'
        self.wciSay = WhatCanISay.WhatCanISay()
        self.interp = CmdInterp()

        # lsa set:
        commands = CmdSet("mixed commands",
                          description="description of commands")
        commands.add_lsa(
            LSAlias(lsa_multiply_spoken_forms,
                    lsa_multiply_meanings,
                    name="multiply"))
        commands.add_lsa(
            LSAlias(lsa_not_spoken_forms, lsa_not_meanings, name="not"))
        commands.add_lsa(
            LSAlias(lsa_not_duplicate_spoken_forms,
                    lsa_not_meanings,
                    name="not"))
        commands.add_lsa(
            LSAlias(lsa_equals_spoken_forms,
                    lsa_equals_meanings,
                    name="equals lsa"))
        # also add an equals csc to these commands:
        commands.add_csc(
            CSCmd(spoken_forms=csc_equals_spoken_forms,
                  meanings=csc_equals_meanings,
                  docstring=csc_equals_docstring))
        self.interp.add_cmd_set(commands)

        # csc set:
        cscs = CmdSet('csc commands', description='description of CSCS')
        cscs2 = CmdSet('csc commands too',
                       description='description duplicates of CSCS')
        cscs.add_csc(
            CSCmd(spoken_forms=csc_with_arguments_spoken_forms,
                  meanings=csc_with_arguments_meanings,
                  docstring=csc_with_arguments_docstring))

        # here the tricky one: else only for python:
        cscs.add_csc(
            CSCmd(spoken_forms=csc_else_spoken_forms,
                  meanings=csc_python_else_meanings,
                  docstring=csc_python_else_docstring))
        # else duplicate, only for python:
        cscs.add_csc(
            CSCmd(spoken_forms=csc_else_duplicate_spoken_forms,
                  meanings=csc_python_else_meanings,
                  docstring=csc_python_else_docstring))
        # csc_c_else_meanings only for c, group should be : csc commands too!

        # and in another set: else for c! should come in set cscs commands too!!!
        cscs2.add_csc(
            CSCmd(spoken_forms=csc_else_spoken_forms,
                  meanings=csc_c_else_meanings,
                  docstring=csc_c_else_docstring))
        self.interp.add_csc_set(cscs)
        self.interp.add_csc_set(cscs2)

        # punctuation:
        punc = SinglePunctuation(name='standard punctuation')
        punc.add('%', ['percent-sign'])
        punc.create(self.interp)

        self.wciSay.load_commands_from_interpreter(self._app(), self.interp,
                                                   'python')