Skip to content

Commit

Permalink
fixed superscript numbers in output
Browse files Browse the repository at this point in the history
  • Loading branch information
ede1998 committed Oct 3, 2019
1 parent 9c2d829 commit aaa1257
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "dict"
version = "1.4.1"
version = "1.4.2"
authors = ["ede1998 <online@erik-hennig.me>"]
edition = "2018"
description = "A small command-line translator. It queries the dict.cc website for translations."
Expand Down
1 change: 0 additions & 1 deletion TODO.txt

This file was deleted.

1 change: 0 additions & 1 deletion src/formatter.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use crate::translator::{Entries, Suggestions, Translations, Translator};

// TODO should be added to Entries
pub fn print(translator: impl Translator) {
use Entries::*;
match translator.entries() {
Expand Down
16 changes: 8 additions & 8 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,14 @@ fn print_info(arguments: &clap::ArgMatches) {
match subcommand {
args::AVAILABLE => {
println!("The following language pairs are available:");
for (l1,l2) in DictccTranslator::get_available_languages() {
println!(
"{} {} => {} - {}",
l1.get_abbreviation(),
l2.get_abbreviation(),
l1,
l2
);
for (l1, l2) in DictccTranslator::get_available_languages() {
println!(
"{} {} => {} - {}",
l1.get_abbreviation(),
l2.get_abbreviation(),
l1,
l2
);
}
}
args::ABBREVIATIONS => {
Expand Down
23 changes: 22 additions & 1 deletion src/translator/dictcc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ impl DictccTranslator {
for node in element.children() {
match ElementRef::wrap(node) {
Some(node) => {
let undesired_tags = vec!["dfn", "div"];
let undesired_tags = ["dfn", "div", "span"];
if !undesired_tags.contains(&node.value().name()) {
content.push_str(&node.text().collect::<String>());
}
Expand Down Expand Up @@ -379,6 +379,27 @@ mod tests {
Html::parse_document(&result);
}

#[test]
fn no_superscript_numbers() {
use Entries::Translation;
const WORD: &str = "pantomime";
const LANG: LanguagePair = (Language::EN, Language::DE);

let mut translator = DictccTranslator::new();
assert!(translator.set_languages_if_available(LANG));
translator.translate(&WORD);

match translator.entries() {
Translation(t) => {
for (l, r) in t {
assert_eq!(l.chars().any(char::is_numeric), false);
assert_eq!(r.chars().any(char::is_numeric), false);
}
}
_ => panic!("No translations found unexpectedly!"),
}
}

#[test]
fn available_languages() {
let website = read_website("dict-responses/available_languages.html");
Expand Down

0 comments on commit aaa1257

Please sign in to comment.