Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test and ci #3

Merged
merged 3 commits into from
May 31, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions .github/workflows/check_before_merge.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: check_before_merge

on:
pull_request:
branches:
- master

jobs:
test:

runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions/setup-java@v1
with:
java-version: '12.x'
- uses: subosito/flutter-action@v1
with:
flutter-version: '1.17.0'
- run: flutter pub get
- run: flutter analyze
- run: flutter test
17 changes: 17 additions & 0 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import 'package:flutter/material.dart';

void main() {
runApp(MyApp());
}

class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
@override
Widget build(BuildContext context) {
return Container();
}
}
181 changes: 181 additions & 0 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
# Generated by pub
# See https://dart.dev/tools/pub/glossary#lockfile
packages:
archive:
dependency: transitive
description:
name: archive
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.13"
args:
dependency: transitive
description:
name: args
url: "https://pub.dartlang.org"
source: hosted
version: "1.6.0"
async:
dependency: transitive
description:
name: async
url: "https://pub.dartlang.org"
source: hosted
version: "2.4.1"
boolean_selector:
dependency: transitive
description:
name: boolean_selector
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.0"
charcode:
dependency: transitive
description:
name: charcode
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.3"
collection:
dependency: transitive
description:
name: collection
url: "https://pub.dartlang.org"
source: hosted
version: "1.14.12"
convert:
dependency: transitive
description:
name: convert
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.1"
crypto:
dependency: transitive
description:
name: crypto
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.4"
flutter:
dependency: "direct main"
description: flutter
source: sdk
version: "0.0.0"
flutter_test:
dependency: "direct dev"
description: flutter
source: sdk
version: "0.0.0"
image:
dependency: transitive
description:
name: image
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.12"
matcher:
dependency: transitive
description:
name: matcher
url: "https://pub.dartlang.org"
source: hosted
version: "0.12.6"
meta:
dependency: transitive
description:
name: meta
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.8"
path:
dependency: transitive
description:
name: path
url: "https://pub.dartlang.org"
source: hosted
version: "1.6.4"
petitparser:
dependency: transitive
description:
name: petitparser
url: "https://pub.dartlang.org"
source: hosted
version: "2.4.0"
quiver:
dependency: transitive
description:
name: quiver
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.3"
sky_engine:
dependency: transitive
description: flutter
source: sdk
version: "0.0.99"
source_span:
dependency: transitive
description:
name: source_span
url: "https://pub.dartlang.org"
source: hosted
version: "1.7.0"
stack_trace:
dependency: transitive
description:
name: stack_trace
url: "https://pub.dartlang.org"
source: hosted
version: "1.9.3"
stream_channel:
dependency: transitive
description:
name: stream_channel
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.0"
string_scanner:
dependency: transitive
description:
name: string_scanner
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.5"
term_glyph:
dependency: transitive
description:
name: term_glyph
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.0"
test_api:
dependency: transitive
description:
name: test_api
url: "https://pub.dartlang.org"
source: hosted
version: "0.2.15"
typed_data:
dependency: transitive
description:
name: typed_data
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.6"
vector_math:
dependency: transitive
description:
name: vector_math
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.8"
xml:
dependency: transitive
description:
name: xml
url: "https://pub.dartlang.org"
source: hosted
version: "3.6.1"
sdks:
dart: ">=2.6.0 <3.0.0"
54 changes: 54 additions & 0 deletions example/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: example
description: Widget and function to implement hashtag-decorated EditableText and RichText. Decorate the words which start with `#`
version: 0.0.6
author: Santa Takahashi <sun.jp.0212@gmail.com>
homepage: https://github.com/santa112358/hashtagable
repository: https://github.com/santa112358/hashtagable

environment:
sdk: ">=2.1.0 <3.0.0"

dependencies:
flutter:
sdk: flutter

dev_dependencies:
flutter_test:
sdk: flutter

# For information on the generic Dart part of this file, see the
# following page: https://dart.dev/tools/pub/pubspec

# The following section is specific to Flutter.
flutter:

# To add assets to your package, add an assets section, like this:
# assets:
# - images/a_dot_burr.jpeg
# - images/a_dot_ham.jpeg
#
# For details regarding assets in packages, see
# https://flutter.dev/assets-and-images/#from-packages
#
# An image asset can refer to one or more resolution-specific "variants", see
# https://flutter.dev/assets-and-images/#resolution-aware.

# To add custom fonts to your package, add a fonts section here,
# in this "flutter" section. Each entry in this list should have a
# "family" key with the font family name, and a "fonts" key with a
# list giving the asset and other descriptors for the font. For
# example:
# fonts:
# - family: Schyler
# fonts:
# - asset: fonts/Schyler-Regular.ttf
# - asset: fonts/Schyler-Italic.ttf
# style: italic
# - family: Trajan Pro
# fonts:
# - asset: fonts/TrajanPro.ttf
# - asset: fonts/TrajanPro_Bold.ttf
# weight: 700
#
# For details regarding fonts in packages, see
# https://flutter.dev/custom-fonts/#from-packages
107 changes: 103 additions & 4 deletions test/hashtagable_test.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,109 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:hashtagable/annotator.dart';

void main() {
test("hashtagableTest", () {
final source = "aaaa #あcdcdcd";
final result = Annotator().getAnnotations(source);
expect(result.length, 2);
final decoratedColor = Colors.red;
final undecoratedColor = Colors.black;
final annotator = Annotator(
textStyle: TextStyle(color: undecoratedColor),
decoratedStyle: TextStyle(color: decoratedColor));
test("Decorated text Always counted correctly", () {
final source =
"#tag1 あああ #tag2 #高橋3 #たぐ4 #タグ5 eww #tag6 #tag7 #tag8 ararara";
final result = annotator.getAnnotations(source);
final decoratedResult =
result.where((item) => item.style.color == decoratedColor).toList();
expect(decoratedResult.length, 8);
});
test("When source starts from '#',decorates the source", () {
final source = "#aAア亜bB4";
expect(annotator.getAnnotations(source).length, 1);
expect(annotator.getAnnotations(source)[0].style.color, decoratedColor);
});

test("When source doesn't include any tags, return empty list", () {
final source = "aaaaaaaaaaaaaa bbbbbbbbb";
expect(annotator.getAnnotations(source).isEmpty, true);
});

test(
"When source consists of [untagged, tagged], split it and decorate the tagged one",
() {
final source = "abcd #hogehoge";
expect(annotator.getAnnotations(source).length, 2);
expect(annotator.getAnnotations(source)[0].style.color, undecoratedColor);
expect(annotator.getAnnotations(source)[1].style.color, decoratedColor);
});

test(
"When source consists of [tagged, untagged], split it and decorate the tagged one",
() {
final source = "#hogehoge abcd";
expect(annotator.getAnnotations(source).length, 2);
expect(annotator.getAnnotations(source)[1].style.color, undecoratedColor);
expect(annotator.getAnnotations(source)[0].style.color, decoratedColor);
});

test(
"When source consists of [tagged, untagged], split it and decorate the first one",
() {
final source = "abcd #hogehoge #hugahuga abcde";
expect(annotator.getAnnotations(source).length, 5);
expect(annotator.getAnnotations(source)[0].style.color, undecoratedColor);
expect(annotator.getAnnotations(source)[1].style.color, decoratedColor);
expect(annotator.getAnnotations(source)[2].style.color, undecoratedColor);
expect(annotator.getAnnotations(source)[3].style.color, decoratedColor);
expect(annotator.getAnnotations(source)[4].style.color, undecoratedColor);
});

test("When tag includes emoji, split and undecorate the text after emoji",
() {
final source = "#abc😄def";
expect(annotator.getAnnotations(source)[0].range,
const TextRange(start: 0, end: 4));
expect(annotator.getAnnotations(source)[0].style.color, decoratedColor);
});

test(
"When tag doesn't include emoji but text does, it needs to decorate properly",
() {
final source = "#abc def😆";
final res = annotator.getAnnotations(source);
expect(res.length, 2);
expect(res[0].style.color, decoratedColor);
expect(res[1].style.color, undecoratedColor);
});

test("When tag includes symbol, split and undecorate the text after emoji",
() {
final source = "#abc!def";
expect(annotator.getAnnotations(source)[0].range,
const TextRange(start: 0, end: 4));
expect(annotator.getAnnotations(source)[1].style.color, undecoratedColor);
});

test(" 'ー' must be contained in tagged text", () {
final source = "#あーい";
expect(annotator.getAnnotations(source)[0].range,
const TextRange(start: 0, end: 4));
});

test("'_' must be contained in tagged text", () {
final source = "#abc_def";
expect(annotator.getAnnotations(source).length, 1);
});

test("Decoration mustn't started with \n", () {
final source = "\n#hashtag";
expect(annotator.getAnnotations(source).length, 2);
expect(annotator.getAnnotations(source)[1].style.color, decoratedColor);
});

test("Stop decoration if it contains \n", () {
final source = "#hash\ntag";
expect(annotator.getAnnotations(source).length, 2);
expect(annotator.getAnnotations(source)[0].style.color, decoratedColor);
});
}