Skip to content

Commit

Permalink
test: Update test to target more of the sentence value surface.
Browse files Browse the repository at this point in the history
  • Loading branch information
vxern committed Jun 9, 2024
1 parent e08ae59 commit 7a0ef65
Show file tree
Hide file tree
Showing 2 changed files with 121 additions and 21 deletions.
11 changes: 10 additions & 1 deletion src/tatoeba/sentence.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,11 @@ pub type Translation {
language_tag: String,
/// The full name of the language the translation is written in.
language_name: String,
/// Whether the translation has been created for a standalone sentence, i.e. not
/// a translation of a translation.
is_direct: Option(Bool),
/// The direction of writing in the sentence.
writing_direction: WritingDirection,
/// Represents how reliable the translation is.
///
/// Note: This value is reported by Tatoeba as not currently being in use.
Expand All @@ -239,6 +244,8 @@ fn translation(
use language <- result.try(data |> field("lang", optional(string)))
use language_tag <- result.try(data |> field("lang_tag", string))
use language_name <- result.try(data |> field("lang_name", string))
use is_direct <- result.try(data |> optional_field("isDirect", bool))
use writing_direction <- result.try(data |> field("dir", writing_direction))
use correctness <- result.try(data |> field("correctness", int))
use script <- result.try(data |> field("script", optional(string)))
use transcriptions <- result.try(
Expand All @@ -252,6 +259,8 @@ fn translation(
language: language,
language_tag: language_tag,
language_name: language_name,
is_direct: is_direct,
writing_direction: writing_direction,
correctness: correctness,
script: script,
transcriptions: transcriptions,
Expand Down Expand Up @@ -413,7 +422,7 @@ pub type Sentence {
///
/// This value can be `None` in the case that a user is suspended or otherwise.
owner: Option(User),
/// The direction of writing applied to the sentence.
/// The direction of writing in the sentence.
writing_direction: WritingDirection,
/// Indicates whether the sentence is favorited by the current user.
///
Expand Down
131 changes: 111 additions & 20 deletions test/sentence_test.gleam
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
import gleam/list
import gleam/option.{None, Some}
import gleeunit
import gleeunit/should
import tatoeba/sentence

pub fn main() {
gleeunit.main()
}

pub fn new_id_test() {
sentence.new_id(1)
|> should.be_ok()
Expand Down Expand Up @@ -55,38 +51,133 @@ pub fn sentence_removed_test() {
}

pub fn sentence_test() {
let assert Ok(id) = sentence.new_id(12_212_258)
let assert Ok(id) = sentence.new_id(1)
let assert Ok(Some(sentence)) = sentence.get(id)

sentence.id |> should.equal(12_212_258)
sentence.text |> should.equal("This work is free of charge.")
sentence.language |> should.equal(Some("eng"))
sentence.language_tag |> should.equal("en")
sentence.language_name |> should.equal("English")
sentence.script |> should.equal(None)
sentence.id |> should.equal(1)
sentence.text |> should.equal("我們試試看!")
sentence.language |> should.equal(Some("cmn"))
sentence.language_tag |> should.equal("zh-Hant")
sentence.language_name |> should.equal("Mandarin Chinese")
sentence.script |> should.equal(Some("Hant"))
sentence.license |> should.equal("CC BY 2.0 FR")
sentence.based_on_id |> should.equal(Some(5_686_783))
sentence.based_on_id |> should.equal(None)
sentence.correctness |> should.equal(0)
sentence.translations
|> list.take(5)
|> should.equal([
sentence.Translation(
id: 5_686_783,
text: "Această lucrare nu se plătește.",
language: Some("ron"),
language_tag: "ro",
language_name: "Romanian",
id: 433_979,
text: "لنحاول !",
language: Some("ara"),
language_tag: "ar",
language_name: "Arabic",
is_direct: Some(True),
writing_direction: sentence.RightToLeft,
correctness: 0,
script: None,
transcriptions: [],
audios: [],
),
sentence.Translation(
id: 2_608_341,
text: "আমরা একবার চেষ্টা করেই দেখি!",
language: Some("ben"),
language_tag: "bn",
language_name: "Bengali",
is_direct: Some(True),
writing_direction: sentence.LeftToRight,
correctness: 0,
script: None,
transcriptions: [],
audios: [],
),
sentence.Translation(
id: 2_604_674,
text: "Ad neɛreḍ!",
language: Some("ber"),
language_tag: "ber",
language_name: "Berber",
is_direct: Some(True),
writing_direction: sentence.LeftToRight,
correctness: 0,
script: None,
transcriptions: [],
audios: [],
),
sentence.Translation(
id: 760_627,
text: "Да пробваме!",
language: Some("bul"),
language_tag: "bg",
language_name: "Bulgarian",
is_direct: Some(True),
writing_direction: sentence.LeftToRight,
correctness: 0,
script: None,
transcriptions: [],
audios: [],
),
sentence.Translation(
id: 826_600,
text: "Versuchen wir's!",
language: Some("deu"),
language_tag: "de",
language_name: "German",
is_direct: Some(True),
writing_direction: sentence.LeftToRight,
correctness: 0,
script: None,
transcriptions: [],
audios: [
sentence.Audio(
id: 497_098,
is_external: None,
author: Some("quicksanddiver"),
attribution_url: Some("/en/user/profile/quicksanddiver"),
license: Some(""),
),
],
),
])
sentence.user_sentences |> should.equal(None)
sentence.list_ids |> should.equal(None)
sentence.transcriptions |> should.equal([])
sentence.transcriptions
|> should.equal([
sentence.Transcription(
id: 1_991_078,
text: "我们试试看!",
sentence_id: 1,
script: Some("Hans"),
transcription_type: sentence.AlternativeScript,
last_modified: "2020-05-13T15:11:29+00:00",
owner_id: None,
owner: None,
html: "我们试试看!",
markup: None,
info_message: "This alternative script was generated automatically.",
is_readonly: True,
needs_review: False,
),
sentence.Transcription(
id: 1_554_809,
text: "Wo3men5 shi4shi5 kan4!",
sentence_id: 1,
script: Some("Latn"),
transcription_type: sentence.ForeignTranscription,
last_modified: "2019-10-18T19:16:22+00:00",
owner_id: Some(81_071),
owner: Some(sentence.User(claimed_native: None, username: "Yorwba")),
html: "Wǒmen sh&igrave;shi k&agrave;n!",
markup: None,
info_message: "Last edited by Yorwba on October 18, 2019 at 7:16:22 PM UTC",
is_readonly: False,
needs_review: False,
),
])
sentence.audios |> should.equal([])
sentence.owner
|> should.equal(Some(sentence.User(claimed_native: None, username: "vxern")))
|> should.equal(Some(sentence.User(claimed_native: None, username: "sysko")))
sentence.writing_direction |> should.equal(sentence.LeftToRight)
sentence.is_favorite |> should.equal(None)
sentence.is_owned_by_current_user |> should.equal(False)
Expand Down

0 comments on commit 7a0ef65

Please sign in to comment.