1
0
mirror of https://github.com/h7x4/unofficial_jisho_api_dart.git synced 2025-09-21 04:55:56 +02:00

Debug local functions

This commit is contained in:
2020-04-26 13:43:38 +02:00
parent a1a99a90dd
commit 763924531f
3 changed files with 199 additions and 13 deletions

View File

@@ -1,6 +1,8 @@
import 'package:unofficial_jisho_api/src/objects.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;
void test_local_functions() async {
@@ -56,7 +58,24 @@ void test_local_functions() async {
});
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', () {
@@ -76,23 +95,101 @@ void test_local_functions() async {
});
test('getYomiExamples', () {
final result = getYomiExamples(kanjiPage, 'Kun');
expect(result, ['']); //FIX
final result = getYomiExamples(kanjiPage, 'On');
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);
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', () {
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', () {
final result = getRadical(kanjiPage);
expect(result, ['']); //FIX
expect(
json.encode(result),
json.encode(Radical(
symbol: '',
meaning: 'sun, day'
))
);
});
test('getParts', () {
@@ -112,11 +209,83 @@ void test_local_functions() async {
test('getNewspaperFrequencyRank', () {
final result = getNewspaperFrequencyRank(kanjiPage);
expect(result, 16); //This might change
expect(result, 16);
});
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 */