Skip to content

Commit

Permalink
Disable Spellcheck by default and remove default words.
Browse files Browse the repository at this point in the history
  • Loading branch information
huacnlee committed May 6, 2022
1 parent 6b51fa9 commit 988a2db
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 6 deletions.
7 changes: 1 addition & 6 deletions autocorrect/.autocorrectrc.default
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
spellcheck:
mode: 1
mode: 0
words:
# Please do not add a general English word (eg. apple, python) here.
# Users can add their special words to their .autocorrectrc file by their need.
- iOS
- iPad
- iPhone
- Wi-Fi
- wifi = Wi-Fi
15 changes: 15 additions & 0 deletions autocorrect/benches/example.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,18 @@ use std::fs::File;
use std::io::Read;
use std::path::Path;

static STEUP_ONCE: std::sync::Once = std::sync::Once::new();

#[macro_use]
extern crate bencher;

fn setup() {
STEUP_ONCE.call_once(|| {
let config_str = include_str!("../../autocorrect-cli/.autocorrectrc.template").to_owned();
autocorrect::config::load(&config_str).unwrap();
})
}

#[allow(unused)]
fn fixture(path: &str) -> String {
let current_dir = env::current_dir().unwrap();
Expand Down Expand Up @@ -154,6 +163,8 @@ fn bench_format_json_with_2k_lines(b: &mut Bencher) {
}

fn bench_spellcheck_50(b: &mut Bencher) {
setup();

b.iter(|| {
spellcheck::spellcheck(
"探索 apple 充满创新的世界,选购各式iphone、ipad、apple watch 和 mac",
Expand All @@ -162,10 +173,14 @@ fn bench_spellcheck_50(b: &mut Bencher) {
}

fn bench_spellcheck_100(b: &mut Bencher) {
setup();

b.iter(|| spellcheck::spellcheck("探索 apple 充满创新的世界,选购各式iphone、ipad、apple watch 和 mac、娱乐产品了,iphone 13 新款 - iphone SE 新款 ,并获得相关产品的专家支持服务。"));
}

fn bench_spellcheck_400(b: &mut Bencher) {
setup();

b.iter(|| spellcheck::spellcheck("探索 apple 充满创新的世界,选购各式 iphone、ipad、apple watch 和 mac、娱乐产品了,iphone 13 新款 - iphone SE 新款 ,并获得相关产品的专家支持服务。通过 apple Trade In 换购计划,你可以用符合条件的智能手机来换购新 iphone,享受折抵优惠5。这样一来,你受益,地球也受益。现可在线加入 iphone 年年焕新计划,年年用上新 iphone,享受 AppleCare+ 服务计划,还可选择分期付款*。AirTag 是能帮你轻松追踪各种物品的高手。只要给钥匙串上
挂一个,往背包里塞一个,在打开查找 app 时,除了能追踪自己的 Apple 设备之外,你还能看到钥匙和背包这些物品在哪里。只要放一个 AirTag,钱包在哪里这类问题会迎刃而解。通过查找 app 的全新“物品”标签页,都能让 AirTag 来指示物品位置。"));
}
Expand Down
2 changes: 2 additions & 0 deletions autocorrect/src/code/markdown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ mod tests {

#[test]
fn test_format_markdown() {
crate::config::setup_test();

let example = r###"
---
title: IPAD 和 Ios 接入的不同点
Expand Down
11 changes: 11 additions & 0 deletions autocorrect/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,17 @@ impl Config {
}
}

// Setup config for test for load tests/.autocorrectrc.test
static STEUP_ONCE: std::sync::Once = std::sync::Once::new();

#[allow(unused)]
pub(crate) fn setup_test() {
STEUP_ONCE.call_once(|| {
let config_str = include_str!("../tests/.autocorrectrc.test").to_owned();
crate::config::load(&config_str).unwrap();
})
}

#[derive(PartialEq, Clone, Debug)]
pub enum SpellcheckMode {
Disabled,
Expand Down
6 changes: 6 additions & 0 deletions autocorrect/src/spellcheck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ mod tests {

#[test]
fn test_spellcheck_basic() {
crate::config::setup_test();

let cases = map! [
"ios" => "iOS",
"this is ipad ios website, and the IOS download url" => "this is iPad iOS website, and the iOS download url",
Expand Down Expand Up @@ -78,6 +80,8 @@ mod tests {

#[test]
fn test_speelcheck_cases() {
crate::config::setup_test();

let cases = map! [
"打开 wifi 并找到就近的 WIFI,点击输入 wi-fi 密码" => "打开 Wi-Fi 并找到就近的 Wi-Fi,点击输入 Wi-Fi 密码"
];
Expand All @@ -86,6 +90,8 @@ mod tests {

#[test]
fn test_spellcheck_all() {
crate::config::setup_test();

let words = Config::current().spellcheck.words.clone();
for l in words.iter() {
let mut left = l.as_str();
Expand Down
8 changes: 8 additions & 0 deletions autocorrect/tests/.autocorrectrc.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
spellcheck:
mode: 1
words:
- iOS
- iPad
- iPhone
- Wi-Fi
- wifi = Wi-Fi

0 comments on commit 988a2db

Please sign in to comment.