Debug local functions
This commit is contained in:
parent
a1a99a90dd
commit
763924531f
|
@ -69,11 +69,20 @@ class YomiExample {
|
||||||
String reading;
|
String reading;
|
||||||
String meaning;
|
String meaning;
|
||||||
|
|
||||||
YomiExample({String example, String reading, String meaning}){
|
YomiExample({String example, String reading, String meaning})
|
||||||
|
{
|
||||||
this.example = example;
|
this.example = example;
|
||||||
this.reading = reading;
|
this.reading = reading;
|
||||||
this.meaning = meaning;
|
this.meaning = meaning;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Map<String, String> toJson() =>
|
||||||
|
{
|
||||||
|
'example': example,
|
||||||
|
'reading': reading,
|
||||||
|
'meaning': meaning
|
||||||
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class Radical {
|
class Radical {
|
||||||
|
@ -86,6 +95,14 @@ class Radical {
|
||||||
this.forms = forms;
|
this.forms = forms;
|
||||||
this.meaning = meaning;
|
this.meaning = meaning;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Map<String, dynamic> toJson() =>
|
||||||
|
{
|
||||||
|
'symbol': symbol,
|
||||||
|
'forms': forms,
|
||||||
|
'meaning': meaning
|
||||||
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class KanjiResult {
|
class KanjiResult {
|
||||||
|
|
|
@ -90,7 +90,7 @@ List<YomiExample> getYomiExamples(String pageHtml, String yomiLocatorSymbol) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
final regex = RegExp(r'/<li>(.*?)<\/li>');
|
final regex = RegExp(r'<li>(.*?)<\/li>', dotAll: true);
|
||||||
final regexResults = getAllGlobalGroupMatches(exampleSection, regex).map((s) => s.trim());
|
final regexResults = getAllGlobalGroupMatches(exampleSection, regex).map((s) => s.trim());
|
||||||
|
|
||||||
final examples = regexResults.map((regexResult) {
|
final examples = regexResults.map((regexResult) {
|
||||||
|
@ -182,9 +182,9 @@ List<String> getParts(String pageHtml) {
|
||||||
}
|
}
|
||||||
|
|
||||||
String getSvgUri(String pageHtml) {
|
String getSvgUri(String pageHtml) {
|
||||||
var svgRegex = RegExp('\/\/.*?.cloudfront.net\/.*?.svg/');
|
var svgRegex = RegExp('\/\/.*?.cloudfront.net\/.*?.svg');
|
||||||
final regexResult = svgRegex.firstMatch(pageHtml).toString();
|
final regexResult = svgRegex.firstMatch(pageHtml).group(0).toString();
|
||||||
return regexResult ?? 'http:${regexResult}';
|
return regexResult.isNotEmpty ? 'http:${regexResult}' : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
String getGifUri(String kanji) {
|
String getGifUri(String kanji) {
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
|
import 'package:unofficial_jisho_api/src/objects.dart';
|
||||||
import 'package:unofficial_jisho_api/unofficial_jisho_api.dart';
|
import 'package:unofficial_jisho_api/unofficial_jisho_api.dart';
|
||||||
import 'package:test/test.dart';
|
|
||||||
|
|
||||||
|
import 'package:test/test.dart';
|
||||||
|
import 'dart:convert';
|
||||||
import 'package:http/http.dart' as http;
|
import 'package:http/http.dart' as http;
|
||||||
|
|
||||||
void test_local_functions() async {
|
void test_local_functions() async {
|
||||||
|
@ -56,7 +58,24 @@ void test_local_functions() async {
|
||||||
});
|
});
|
||||||
|
|
||||||
test('parseAnchorsToArray', () {
|
test('parseAnchorsToArray', () {
|
||||||
|
const htmlCode =
|
||||||
|
'''
|
||||||
|
<div class="test">
|
||||||
|
<p>
|
||||||
|
<a href="https://test.test">Hello</a>
|
||||||
|
</p>
|
||||||
|
<a href="//xyz">Hi</a>
|
||||||
|
<span>
|
||||||
|
<p>
|
||||||
|
<a href="">How are you doing</a>
|
||||||
|
</p>
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
''';
|
||||||
|
|
||||||
|
final result = parseAnchorsToArray(htmlCode);
|
||||||
|
expect(result, [
|
||||||
|
'Hello', 'Hi', 'How are you doing']);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('getYomi', () {
|
test('getYomi', () {
|
||||||
|
@ -76,23 +95,101 @@ void test_local_functions() async {
|
||||||
});
|
});
|
||||||
|
|
||||||
test('getYomiExamples', () {
|
test('getYomiExamples', () {
|
||||||
final result = getYomiExamples(kanjiPage, 'Kun');
|
final result = getYomiExamples(kanjiPage, 'On');
|
||||||
expect(result, ['ジ']); //FIX
|
expect(
|
||||||
|
json.encode(result),
|
||||||
|
json.encode([
|
||||||
|
YomiExample(
|
||||||
|
example: '時',
|
||||||
|
reading: 'ジ',
|
||||||
|
meaning: '''hour, o'clock, (specified) time, when ..., during ...'''
|
||||||
|
),
|
||||||
|
YomiExample(
|
||||||
|
example: '時価',
|
||||||
|
reading: 'ジカ',
|
||||||
|
meaning: 'current value, price, market value'
|
||||||
|
),
|
||||||
|
YomiExample(
|
||||||
|
example: '零時',
|
||||||
|
reading: 'レイジ',
|
||||||
|
meaning: '''twelve o'clock, midnight, noon'''
|
||||||
|
),
|
||||||
|
YomiExample(
|
||||||
|
example: '平時',
|
||||||
|
reading: 'ヘイジ',
|
||||||
|
meaning: 'peacetime, time of peace, ordinary times, normal times'
|
||||||
|
),
|
||||||
|
])
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('getOnomiExamples', () {
|
test('getOnyomiExamples', () {
|
||||||
final result = getOnyomiExamples(kanjiPage);
|
final result = getOnyomiExamples(kanjiPage);
|
||||||
expect(result, ['ジ']); //FIX
|
expect(
|
||||||
|
json.encode(result),
|
||||||
|
json.encode([
|
||||||
|
YomiExample(
|
||||||
|
example: '時',
|
||||||
|
reading: 'ジ',
|
||||||
|
meaning: '''hour, o'clock, (specified) time, when ..., during ...'''
|
||||||
|
),
|
||||||
|
YomiExample(
|
||||||
|
example: '時価',
|
||||||
|
reading: 'ジカ',
|
||||||
|
meaning: 'current value, price, market value'
|
||||||
|
),
|
||||||
|
YomiExample(
|
||||||
|
example: '零時',
|
||||||
|
reading: 'レイジ',
|
||||||
|
meaning: '''twelve o'clock, midnight, noon'''
|
||||||
|
),
|
||||||
|
YomiExample(
|
||||||
|
example: '平時',
|
||||||
|
reading: 'ヘイジ',
|
||||||
|
meaning: 'peacetime, time of peace, ordinary times, normal times'
|
||||||
|
),
|
||||||
|
])
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('getKunyomiExamples', () {
|
test('getKunyomiExamples', () {
|
||||||
final result = getKunyomiExamples(kanjiPage);
|
final result = getKunyomiExamples(kanjiPage);
|
||||||
expect(result, ['ジ']); //FIX
|
expect(
|
||||||
|
json.encode(result),
|
||||||
|
json.encode([
|
||||||
|
YomiExample(
|
||||||
|
example: '時',
|
||||||
|
reading: 'とき',
|
||||||
|
meaning: 'time, hour, moment, occasion, case, chance, opportunity, season, the times, the age, the day, tense'
|
||||||
|
),
|
||||||
|
YomiExample(
|
||||||
|
example: '時折',
|
||||||
|
reading: 'ときおり',
|
||||||
|
meaning: 'sometimes'
|
||||||
|
),
|
||||||
|
YomiExample(
|
||||||
|
example: '切り替え時',
|
||||||
|
reading: 'きりかえとき',
|
||||||
|
meaning: 'time to switch over, response time'
|
||||||
|
),
|
||||||
|
YomiExample(
|
||||||
|
example: '逢魔が時',
|
||||||
|
reading: 'おうまがとき',
|
||||||
|
meaning: '''twilight, time for disasters (similar to 'the witching hour' but not midnight)'''
|
||||||
|
),
|
||||||
|
])
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('getRadical', () {
|
test('getRadical', () {
|
||||||
final result = getRadical(kanjiPage);
|
final result = getRadical(kanjiPage);
|
||||||
expect(result, ['ジ']); //FIX
|
expect(
|
||||||
|
json.encode(result),
|
||||||
|
json.encode(Radical(
|
||||||
|
symbol: '日',
|
||||||
|
meaning: 'sun, day'
|
||||||
|
))
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('getParts', () {
|
test('getParts', () {
|
||||||
|
@ -112,11 +209,83 @@ void test_local_functions() async {
|
||||||
|
|
||||||
test('getNewspaperFrequencyRank', () {
|
test('getNewspaperFrequencyRank', () {
|
||||||
final result = getNewspaperFrequencyRank(kanjiPage);
|
final result = getNewspaperFrequencyRank(kanjiPage);
|
||||||
expect(result, 16); //This might change
|
expect(result, 16);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('parseKanjiPageData', () {
|
test('parseKanjiPageData', () {
|
||||||
|
final result = parseKanjiPageData(kanjiPage, '時');
|
||||||
|
|
||||||
|
final expectedResult = KanjiResult();
|
||||||
|
expectedResult.query = '時';
|
||||||
|
expectedResult.found = true;
|
||||||
|
expectedResult.taughtIn = 'grade 2';
|
||||||
|
expectedResult.jlptLevel = 'N5';
|
||||||
|
expectedResult.newspaperFrequencyRank = 16;
|
||||||
|
expectedResult.strokeCount = 10;
|
||||||
|
expectedResult.meaning = 'time, hour';
|
||||||
|
expectedResult.kunyomi = ['とき', '-どき'];
|
||||||
|
expectedResult.onyomi = ['ジ'];
|
||||||
|
expectedResult.onyomiExamples =
|
||||||
|
[
|
||||||
|
YomiExample(
|
||||||
|
example: '時',
|
||||||
|
reading: 'ジ',
|
||||||
|
meaning: '''hour, o'clock, (specified) time, when ..., during ...'''
|
||||||
|
),
|
||||||
|
YomiExample(
|
||||||
|
example: '時価',
|
||||||
|
reading: 'ジカ',
|
||||||
|
meaning: 'current value, price, market value'
|
||||||
|
),
|
||||||
|
YomiExample(
|
||||||
|
example: '零時',
|
||||||
|
reading: 'レイジ',
|
||||||
|
meaning: '''twelve o'clock, midnight, noon'''
|
||||||
|
),
|
||||||
|
YomiExample(
|
||||||
|
example: '平時',
|
||||||
|
reading: 'ヘイジ',
|
||||||
|
meaning: 'peacetime, time of peace, ordinary times, normal times'
|
||||||
|
),
|
||||||
|
];
|
||||||
|
expectedResult.kunyomiExamples =
|
||||||
|
[
|
||||||
|
YomiExample(
|
||||||
|
example: '時',
|
||||||
|
reading: 'とき',
|
||||||
|
meaning: 'time, hour, moment, occasion, case, chance, opportunity, season, the times, the age, the day, tense'
|
||||||
|
),
|
||||||
|
YomiExample(
|
||||||
|
example: '時折',
|
||||||
|
reading: 'ときおり',
|
||||||
|
meaning: 'sometimes'
|
||||||
|
),
|
||||||
|
YomiExample(
|
||||||
|
example: '切り替え時',
|
||||||
|
reading: 'きりかえとき',
|
||||||
|
meaning: 'time to switch over, response time'
|
||||||
|
),
|
||||||
|
YomiExample(
|
||||||
|
example: '逢魔が時',
|
||||||
|
reading: 'おうまがとき',
|
||||||
|
meaning: '''twilight, time for disasters (similar to 'the witching hour' but not midnight)'''
|
||||||
|
),
|
||||||
|
];
|
||||||
|
expectedResult.radical =
|
||||||
|
Radical(
|
||||||
|
symbol: '日',
|
||||||
|
meaning: 'sun, day'
|
||||||
|
);
|
||||||
|
expectedResult.parts = ['土', '寸', '日'];
|
||||||
|
expectedResult.strokeOrderDiagramUri = 'https://classic.jisho.org/static/images/stroke_diagrams/26178_frames.png';
|
||||||
|
expectedResult.strokeOrderSvgUri = 'http://d1w6u4xc3l95km.cloudfront.net/kanji-2015-03/06642.svg';
|
||||||
|
expectedResult.strokeOrderGifUri = 'https://raw.githubusercontent.com/mistval/kanji_images/master/gifs/3c.gif';
|
||||||
|
expectedResult.uri = 'https://jisho.org/search/%E6%99%82%23kanji';
|
||||||
|
|
||||||
|
expect(
|
||||||
|
json.encode(result),
|
||||||
|
json.encode(expectedResult)
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
/* KANJI SEARCH FUNCTION TESTS END */
|
/* KANJI SEARCH FUNCTION TESTS END */
|
||||||
|
|
Loading…
Reference in New Issue