Added test cases for Dart support for CPD.

This commit is contained in:
Maikel Steneker
2019-04-05 17:04:49 +02:00
parent 8db2026735
commit 745ebc461c
4 changed files with 121 additions and 0 deletions

View File

@ -0,0 +1,56 @@
/**
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
package net.sourceforge.pmd.cpd;
import java.io.IOException;
import java.util.Arrays;
import java.util.Collection;
import org.apache.commons.io.IOUtils;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import net.sourceforge.pmd.testframework.AbstractTokenizerTest;
@RunWith(Parameterized.class)
public class DartTokenizerTest extends AbstractTokenizerTest {
private final String filename;
private final int nExpectedTokens;
public DartTokenizerTest(String filename, int nExpectedTokens) {
this.filename = filename;
this.nExpectedTokens = nExpectedTokens;
}
@Parameterized.Parameters
public static Collection<Object[]> data() {
return Arrays.asList(
new Object[] { "comment.dart" , 5 },
new Object[] { "increment.dart" , 185 },
new Object[] { "imports.dart" , 1 }
);
}
@Before
@Override
public void buildTokenizer() throws IOException {
this.tokenizer = new DartTokenizer();
this.sourceCode = new SourceCode(new SourceCode.StringCodeLoader(this.getSampleCode(), this.filename));
}
@Override
public String getSampleCode() throws IOException {
return IOUtils.toString(DartTokenizer.class.getResourceAsStream(this.filename));
}
@Test
public void tokenizeTest() throws IOException {
this.expectedTokenCount = nExpectedTokens;
super.tokenizeTest();
}
}

View File

@ -0,0 +1,26 @@
library mylibrary;
var x = 0;
/*
void increment1() { x += 1; }
void increment2() { x += 1; }
void increment3() { x += 1; }
void increment4() { x += 1; }
void increment5() { x += 1; }
void increment6() { x += 1; }
void increment7() { x += 1; }
void increment8() { x += 1; }
void increment9() { x += 1; }
void increment10() { x += 1; }
void increment11() { x += 1; }
void increment12() { x += 1; }
void increment13() { x += 1; }
void increment14() { x += 1; }
void increment15() { x += 1; }
void increment16() { x += 1; }
void increment17() { x += 1; }
void increment18() { x += 1; }
void increment19() { x += 1; }
void increment20() { x += 1; }
*/

View File

@ -0,0 +1,15 @@
import 'package:flutter/material.dart';
import 'package:english_words/english_words.dart' as EnglishWords;
import 'dart:io' deferred as io;
import 'dart:async' show AsyncError hide Completer;
import 'dart:async' hide Completer show AsyncError;
import 'dart:async' show AsyncError;
import 'dart:async' hide Completer;
import 'dart:async' show AsyncError, Completer hide ControllerCallback, ControllerCancelCallback;
import 'dart:async' show AsyncError, Completer;
import 'dart:async' hide ControllerCallback, ControllerCancelCallback;
import "package:boolean_selector/boolean_selector.dart";
import '''package:charcode/ascii.dart''' as ascii;
import """package:collection/algorithms.dart""" as algo;
import 'dart:collection' show HashMap;
import 'dart:math' hide ln10 show ln2, cos, sin;

View File

@ -0,0 +1,24 @@
library mylibrary;
var x = 0;
void increment1() { x += 1; }
void increment2() { x += 1; }
void increment3() { x += 1; }
void increment4() { x += 1; }
void increment5() { x += 1; }
void increment6() { x += 1; }
void increment7() { x += 1; }
void increment8() { x += 1; }
void increment9() { x += 1; }
void increment10() { x += 1; }
void increment11() { x += 1; }
void increment12() { x += 1; }
void increment13() { x += 1; }
void increment14() { x += 1; }
void increment15() { x += 1; }
void increment16() { x += 1; }
void increment17() { x += 1; }
void increment18() { x += 1; }
void increment19() { x += 1; }
void increment20() { x += 1; }