Example #1
0
def FileReadyToParse_Diagnostics_Simple_test( app ):
  filepath = ProjectPath( 'TestFactory.java' )
  contents = ReadFile( filepath )

  # It can take a while for the diagnostics to be ready
  results = WaitForDiagnosticsToBeReady( app, filepath, contents, 'java' )
  print( 'completer response: {0}'.format( pformat( results ) ) )

  assert_that( results, DIAG_MATCHERS_PER_FILE[ filepath ] )
Example #2
0
def Diagnostics_FileReadyToParse_test( app ):
  filepath = PathToTestFile( 'common', 'src', 'main.rs' )
  contents = ReadFile( filepath )

  # It can take a while for the diagnostics to be ready.
  results = WaitForDiagnosticsToBeReady( app, filepath, contents, 'rust' )
  print( f'completer response: { pformat( results ) }' )

  assert_that( results, DIAG_MATCHERS_PER_FILE[ filepath ] )
Example #3
0
def FileReadyToParse_ChangeFileContentsFileData_test( app ):
  filepath = TestFactory
  contents = ReadFile( filepath )
  unsaved_buffer_path = TestLauncher
  file_data = {
    unsaved_buffer_path: {
      'contents': 'package com.test; public class TestLauncher {}',
      'filetypes': [ 'java' ],
    }
  }

  StartJavaCompleterServerInDirectory( app, ProjectPath() )

  # It can take a while for the diagnostics to be ready
  results = WaitForDiagnosticsToBeReady( app, filepath, contents, 'java' )
  assert results

  # Check that we have diagnostics for the saved file
  diags = _WaitForDiagnosticsForFile( app,
                                      filepath,
                                      contents,
                                      unsaved_buffer_path,
                                      lambda d: d )
  assert_that( diags, DIAG_MATCHERS_PER_FILE[ unsaved_buffer_path ] )

  # Now update the unsaved file with new contents
  event_data = BuildRequest( event_name = 'FileReadyToParse',
                             contents = contents,
                             filepath = filepath,
                             filetype = 'java',
                             file_data = file_data )
  app.post_json( '/event_notification', event_data )

  # Check that we have no diagnostics for the dirty file
  diags = _WaitForDiagnosticsForFile( app,
                                      filepath,
                                      contents,
                                      unsaved_buffer_path,
                                      lambda d: not d )
  assert_that( diags, empty() )

  # Now send the request again, but don't include the unsaved file. It should be
  # read from disk, casuing the diagnostics for that file to appear.
  event_data = BuildRequest( event_name = 'FileReadyToParse',
                             contents = contents,
                             filepath = filepath,
                             filetype = 'java' )
  app.post_json( '/event_notification', event_data )

  # Check that we now have diagnostics for the previously-dirty file
  diags = _WaitForDiagnosticsForFile( app,
                                      filepath,
                                      contents,
                                      unsaved_buffer_path,
                                      lambda d: d )

  assert_that( diags, DIAG_MATCHERS_PER_FILE[ unsaved_buffer_path ] )
Example #4
0
def Diagnostics_FileReadyToParse_test( app ):
  filepath = PathToTestFile( 'goto.go' )
  contents = ReadFile( filepath )

  # It can take a while for the diagnostics to be ready.
  results = WaitForDiagnosticsToBeReady( app, filepath, contents, 'go' )
  print( 'completer response: {}'.format( pformat( results ) ) )

  assert_that( results, DIAG_MATCHERS_PER_FILE[ filepath ] )
Example #5
0
def Diagnostics_DetailedDiags_test( app ):
  filepath = PathToTestFile( 'goto.go' )
  contents = ReadFile( filepath )
  WaitForDiagnosticsToBeReady( app, filepath, contents, 'go' )
  request_data = BuildRequest( contents = contents,
                               filepath = filepath,
                               filetype = 'go',
                               line_num = 12,
                               column_num = 5 )

  results = app.post_json( '/detailed_diagnostic', request_data ).json
  assert_that( results,
               has_entry( 'message', 'undeclared name: diagnostics_test' ) )
Example #6
0
def Diagnostics_DetailedDiags_test( app ):
  filepath = PathToTestFile( 'common', 'src', 'main.rs' )
  contents = ReadFile( filepath )
  WaitForDiagnosticsToBeReady( app, filepath, contents, 'rust' )
  request_data = BuildRequest( contents = contents,
                               filepath = filepath,
                               filetype = 'rust',
                               line_num = 14,
                               column_num = 13 )

  results = app.post_json( '/detailed_diagnostic', request_data ).json
  assert_that( results, has_entry(
      'message',
      'no field `build_` on type `test::Builder`\nunknown field' ) )
Example #7
0
  def test_Diagnostics_DetailedDiags( self, app ):
    filepath = TestFactory
    contents = ReadFile( filepath )
    WaitForDiagnosticsToBeReady( app, filepath, contents, 'java' )
    request_data = BuildRequest( contents = contents,
                                 filepath = filepath,
                                 filetype = 'java',
                                 line_num = 15,
                                 column_num = 19 )

    results = app.post_json( '/detailed_diagnostic', request_data ).json
    assert_that( results, has_entry(
        'message',
        'The value of the field TestFactory.Bar.testString is not used' ) )
Example #8
0
    def test_Diagnostics_FileReadyToParse(self, app):
        filepath = PathToTestFile('common', 'src', 'main.rs')
        contents = ReadFile(filepath)
        with open(filepath, 'w') as f:
            f.write(contents)
        event_data = BuildRequest(event_name='FileSave',
                                  contents=contents,
                                  filepath=filepath,
                                  filetype='rust')
        app.post_json('/event_notification', event_data)

        # It can take a while for the diagnostics to be ready.
        results = WaitForDiagnosticsToBeReady(app, filepath, contents, 'rust')
        print(f'completer response: { pformat( results ) }')

        assert_that(results, DIAG_MATCHERS_PER_FILE[filepath])
Example #9
0
    def test_Diagnostics_DetailedDiags(self, app):
        filepath = PathToTestFile('common', 'src', 'main.rs')
        contents = ReadFile(filepath)
        with open(filepath, 'w') as f:
            f.write(contents)
        event_data = BuildRequest(event_name='FileSave',
                                  contents=contents,
                                  filepath=filepath,
                                  filetype='rust')
        app.post_json('/event_notification', event_data)

        WaitForDiagnosticsToBeReady(app, filepath, contents, 'rust')
        request_data = BuildRequest(contents=contents,
                                    filepath=filepath,
                                    filetype='rust',
                                    line_num=14,
                                    column_num=13)

        results = app.post_json('/detailed_diagnostic', request_data).json
        assert_that(
            results,
            has_entry(
                'message',
                'no field `build_` on type `test::Builder`\nunknown field'))