fibonacci

in ee/spec/lib/code_suggestions/instructions_extractor_spec.rb [167:407]


            def fibonacci(x)

          CODE
        end

        it_behaves_like 'extracted instruction' do
          let(:trigger_type) { 'small_file' }
        end
      end

      context 'when there are some lines above the comment' do
        let(:content_above_cursor) do
          <<~CODE
            full_name()
            address()

            
          CODE
        end

        it_behaves_like 'extracted instruction' do
          let(:instruction) { '' }
          let(:trigger_type) { 'comment' }
        end
      end

      context 'when there are several comment in a row' do
        let(:content_above_cursor) do
          <<~CODE
            full_name()
            address()

            
            
            
          CODE
        end

        it_behaves_like 'extracted instruction' do
          let(:instruction) { '' }
          let(:trigger_type) { 'comment' }
        end
      end

      context 'when there are several comments in a row followed by empty line' do
        let(:content_above_cursor) do
          <<~CODE
            full_name()
            address()

            
            
            
          CODE
        end

        it_behaves_like 'extracted instruction' do
          let(:instruction) { '' }
          let(:trigger_type) { 'comment' }
        end
      end

      context 'when there are several comments in a row followed by empty lines' do
        let(:content_above_cursor) do
          <<~CODE
            full_name()
            address()
            street()
            city()
            state()
            pincode()

            
            
            


          CODE
        end

        it { is_expected.to be_nil }
      end

      context 'when there are several comments in a row followed by other code' do
        let(:content_above_cursor) do
          <<~CODE
            full_name()
            address()
            street()
            city()
            state()
            pincode()

            
            
            
            other_code()
          CODE
        end

        it { is_expected.to be_nil }
      end

      context 'when the first line of multiline comment does not meet requirements' do
        let(:content_above_cursor) do
          <<~CODE
            full_name()
            address()

            
            
            another_function()

            
            
            
            
          CODE
        end

        let(:expected_content_above_cursor) do
          <<~CODE
            full_name()
            address()

            
            
            another_function()
          CODE
        end

        it_behaves_like 'extracted instruction' do
          let(:trigger_type) { 'small_file' }
        end
      end

      context 'when there is content_above_cursor between comment lines' do
        let(:content_above_cursor) do
          <<~CODE
            full_name()
            address()
            street()
            city()
            state()
            pincode()


            
            

            
          CODE
        end

        it "does not find instruction" do
          is_expected.to be_nil
        end
      end
    end

    context 'when content_above_cursor is a supported language' do
      include_context 'with comment contents_above_cursor'

      languages_with_single_line_comment_content_above_cursor.each do |lang, content_above_cursor|
        context "when using language #{lang} and content_above_cursor #{content_above_cursor}" do
          let(:language) { CodeSuggestions::ProgrammingLanguage.new(lang) }
          let(:comment_sign) { content_above_cursor }

          it_behaves_like 'detects comments correctly'
        end
      end
    end

    context 'when cursor is inside an empty method' do
      let(:language) do
        CodeSuggestions::ProgrammingLanguage.new('Python')
      end

      let(:instruction) do
        <<~INSTRUCTION
          Complete the empty function and generate contents based on the function name and signature.
          Do not repeat the code. Only return the method contents.
        INSTRUCTION
      end

      let(:content_above_cursor) do
        <<~CONTENT_ABOVE_CURSOR
          def func0():
            return 0

          def func2():
            return 0

          def func1():
            return 0

          def index(arg1, arg2):

        CONTENT_ABOVE_CURSOR
      end

      context 'when it is at the end of the file' do
        let(:content_below_cursor) { '' }

        it_behaves_like 'extracted instruction' do
          let(:trigger_type) { 'empty_function' }
        end
      end

      context 'when cursor is inside an empty method but middle of the file' do
        let(:content_below_cursor) do
          <<~SUFFIX
            def index2():
              return 0

            def index3(arg1):
              return 1
          SUFFIX
        end

        it_behaves_like 'extracted instruction' do
          let(:trigger_type) { 'empty_function' }
        end
      end

      context 'when cursor in inside a non-empty method' do
        let(:content_below_cursor) do
          <<~SUFFIX
              return 0

            def index2():
              return 'something'
          SUFFIX
        end

        it { is_expected.to be_nil }
      end
    end
  end
end