<commit_before>// Copyright (c) 2017, the Dart project authors.  Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

import 'package:analyzer/src/dart/error/syntactic_errors.dart';
import 'package:test_reflective_loader/test_reflective_loader.dart';

import 'recovery_test_support.dart';

main() {
  defineReflectiveSuite(() {
    defineReflectiveTests(MiscellaneousTest);
    defineReflectiveTests(ModifiersTest);
    defineReflectiveTests(MultipleTypeTest);
    defineReflectiveTests(PunctuationTest);
  });
}

/**
 * Test how well the parser recovers in other cases.
 */
@reflectiveTest
class MiscellaneousTest extends AbstractRecoveryTest {
  @failingTest
  void test_classTypeAlias_withBody() {
    // Parser crashes
    testRecovery('''
class B = Object with A {}
''', [ParserErrorCode.EXPECTED_TOKEN], '''
class B = Object with A;
''');
  }

  void test_getter_parameters() {
    testRecovery('''
int get g() => 0;
''', [ParserErrorCode.GETTER_WITH_PARAMETERS], '''
int get g => 0;
''');
  }

  void test_multipleRedirectingInitializers() {
    testRecovery('''
class A {
  A() : this.a(), this.b();
  A.a() {}
  A.b() {}
}
''', [], '''
class A {
  A() : this.a(), this.b();
  A.a() {}
  A.b() {}
}
''');
  }
}

/**
 * Test how well the parser recovers when extra modifiers are provided.
 */
@reflectiveTest
class ModifiersTest extends AbstractRecoveryTest {
  @failingTest
  void test_classDeclaration_static() {
    // TODO(danrubel): Fails because compilation unit begin token is `static`
    // even after recovery.
    testRecovery('''
static class A {}
''', [ParserErrorCode.EXTRANEOUS_MODIFIER], '''
class A {}
''');
  }
}

@reflectiveTest
class MultipleTypeTest extends AbstractRecoveryTest {
  @failingTest
  void test_topLevelVariable() {
    // https://github.com/dart-lang/sdk/issues/25875
    // Recovers with 'void bar() {}', which seems wrong. Seems like we should
    // keep the first type, not the second.
    testRecovery('''
String void bar() { }
''', [ParserErrorCode.UNEXPECTED_TOKEN], '''
String bar() { }
''');
  }
}

/**
 * Test how well the parser recovers when there is extra punctuation.
 */
@reflectiveTest
class PunctuationTest extends AbstractRecoveryTest {
  void test_extraSemicolon_afterLastClassMember() {
    testRecovery('''
class C {
  foo() {};
}
''', [ParserErrorCode.EXPECTED_CLASS_MEMBER], '''
class C {
  foo() {}
}
''');
  }

  void test_extraSemicolon_afterLastTopLevelMember() {
    testRecovery('''
foo() {};
''', [ParserErrorCode.EXPECTED_EXECUTABLE], '''
foo() {}
''');
  }
<commit_msg>Add a recover test based on issue 22313<commit_after>// Copyright (c) 2017, the Dart project authors.  Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

import 'package:analyzer/src/dart/error/syntactic_errors.dart';
import 'package:test_reflective_loader/test_reflective_loader.dart';

import 'recovery_test_support.dart';

main() {
  defineReflectiveSuite(() {
    defineReflectiveTests(MiscellaneousTest);
    defineReflectiveTests(ModifiersTest);
    defineReflectiveTests(MultipleTypeTest);
    defineReflectiveTests(PunctuationTest);
  });
}

/**
 * Test how well the parser recovers in other cases.
 */
@reflectiveTest
class MiscellaneousTest extends AbstractRecoveryTest {
  @failingTest
  void test_classTypeAlias_withBody() {
    // Parser crashes
    testRecovery('''
class B = Object with A {}
''', [ParserErrorCode.EXPECTED_TOKEN], '''
class B = Object with A;
''');
  }

  void test_getter_parameters() {
    testRecovery('''
int get g() => 0;
''', [ParserErrorCode.GETTER_WITH_PARAMETERS], '''
int get g => 0;
''');
  }

  void test_multipleRedirectingInitializers() {
    testRecovery('''
class A {
  A() : this.a(), this.b();
  A.a() {}
  A.b() {}
}
''', [], '''
class A {
  A() : this.a(), this.b();
  A.a() {}
  A.b() {}
}
''');
  }
}

/**
 * Test how well the parser recovers when extra modifiers are provided.
 */
@reflectiveTest
class ModifiersTest extends AbstractRecoveryTest {
  @failingTest
  void test_classDeclaration_static() {
    // TODO(danrubel): Fails because compilation unit begin token is `static`
    // even after recovery.
    testRecovery('''
static class A {}
''', [ParserErrorCode.EXTRANEOUS_MODIFIER], '''
class A {}
''');
  }
}

@reflectiveTest
class MultipleTypeTest extends AbstractRecoveryTest {
  @failingTest
  void test_topLevelVariable() {
    // https://github.com/dart-lang/sdk/issues/25875
    // Recovers with 'void bar() {}', which seems wrong. Seems like we should
    // keep the first type, not the second.
    testRecovery('''
String void bar() { }
''', [ParserErrorCode.UNEXPECTED_TOKEN], '''
String bar() { }
''');
  }
}

/**
 * Test how well the parser recovers when there is extra punctuation.
 */
@reflectiveTest
class PunctuationTest extends AbstractRecoveryTest {
  @failingTest
  void test_extraComma_extendsClause() {
    // https://github.com/dart-lang/sdk/issues/22313
    testRecovery('''
class A { }
class B { }
class Foo extends A, B {
  Foo() { }
}
''', [ParserErrorCode.UNEXPECTED_TOKEN, ParserErrorCode.UNEXPECTED_TOKEN], '''
class A { }
class B { }
class Foo extends A {
  Foo() { }
}
''');
  }

  void test_extraSemicolon_afterLastClassMember() {
    testRecovery('''
class C {
  foo() {};
}
''', [ParserErrorCode.EXPECTED_CLASS_MEMBER], '''
class C {
  foo() {}
}
''');
  }

  void test_extraSemicolon_afterLastTopLevelMember() {
    testRecovery('''
foo() {};
''', [ParserErrorCode.EXPECTED_EXECUTABLE], '''
foo() {}
''');
  }

{'fraction_non_alphanumeric': 0.14798521907443252, 'fraction_numerical': 0.005630828787612177, 'mean_word_length': 4.125338142470694, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 3, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '11670', 'n_tokens_mistral': 1896, 'n_tokens_neox': 1878, 'n_words': 459}