Started the field that will eventually become a web page.
Some checks failed
Gitea Actions Demo / Explore-Gitea-Actions (push) Failing after 1s
Some checks failed
Gitea Actions Demo / Explore-Gitea-Actions (push) Failing after 1s
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
use chrono::prelude::*;
|
||||
use isolang::Language;
|
||||
use std::{
|
||||
cmp::Ordering,
|
||||
collections::HashMap,
|
||||
ops::{Add, AddAssign},
|
||||
time::Duration,
|
||||
};
|
||||
@@ -13,7 +15,6 @@ pub enum Field {
|
||||
Duration(Duration),
|
||||
Integer(i128),
|
||||
None,
|
||||
Revision(Revision),
|
||||
StaticString(String),
|
||||
Uuid(Uuid),
|
||||
}
|
||||
@@ -70,12 +71,6 @@ impl From<Duration> for Field {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Revision> for Field {
|
||||
fn from(value: Revision) -> Self {
|
||||
Self::Revision(value)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<String> for Field {
|
||||
fn from(value: String) -> Self {
|
||||
Self::StaticString(value)
|
||||
@@ -121,7 +116,6 @@ impl PartialOrd for Field {
|
||||
(Self::DateTime(d1), Self::DateTime(d2)) => d1.partial_cmp(d2),
|
||||
(Self::Duration(d1), Self::Duration(d2)) => d1.partial_cmp(d2),
|
||||
(Self::Integer(d1), Self::Integer(d2)) => d1.partial_cmp(d2),
|
||||
(Self::Revision(d1), Self::Revision(d2)) => d1.partial_cmp(d2),
|
||||
(Self::StaticString(d1), Self::StaticString(d2)) => d1.partial_cmp(d2),
|
||||
(Self::Uuid(d1), Self::Uuid(d2)) => d1.partial_cmp(d2),
|
||||
(_, _) => None,
|
||||
@@ -277,7 +271,6 @@ pub enum FieldType {
|
||||
Duration,
|
||||
Integer,
|
||||
None,
|
||||
Revision,
|
||||
StaticString,
|
||||
Uuid,
|
||||
}
|
||||
@@ -290,7 +283,6 @@ impl FieldType {
|
||||
FieldType::Duration => Duration::from_secs(0).into(),
|
||||
FieldType::Integer => 0.into(),
|
||||
FieldType::None => Field::None,
|
||||
FieldType::Revision => Revision::new().into(),
|
||||
FieldType::StaticString => "".into(),
|
||||
FieldType::Uuid => Uuid::new_v4().into(),
|
||||
}
|
||||
@@ -305,7 +297,6 @@ impl From<&Field> for FieldType {
|
||||
Field::Duration(_) => Self::Duration,
|
||||
Field::Integer(_) => Self::Integer,
|
||||
Field::None => Self::None,
|
||||
Field::Revision(_) => Self::Revision,
|
||||
Field::StaticString(_) => Self::StaticString,
|
||||
Field::Uuid(_) => Self::Uuid,
|
||||
}
|
||||
@@ -348,26 +339,69 @@ mod fieldtypes {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
|
||||
struct Revision;
|
||||
struct Paragraph {
|
||||
data: HashMap<Language, String>,
|
||||
}
|
||||
|
||||
impl Revision {
|
||||
fn new() -> Self {
|
||||
Self {}
|
||||
impl Paragraph {
|
||||
fn new(string: String, lang: Language) -> Self {
|
||||
let mut data = HashMap::new();
|
||||
data.insert(lang, string);
|
||||
Self {
|
||||
data: data,
|
||||
}
|
||||
}
|
||||
|
||||
fn revision(&self) -> isize {
|
||||
0
|
||||
fn add_translation(&mut self, string: String, lang: Language) {
|
||||
self.data.insert(lang, string);
|
||||
}
|
||||
|
||||
fn get(&self, lang: &Language) -> Option<&String> {
|
||||
self.data.get(lang)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod revisions {
|
||||
mod paragraphs {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn can_create_empty_revision() {
|
||||
let rev = Revision::new();
|
||||
assert_eq!(rev.revision(), 0);
|
||||
fn does_paragraph_store_language_information() {
|
||||
let languages = [Language::from_639_1("en").unwrap(), Language::from_639_1("ja").unwrap()];
|
||||
let data = Uuid::new_v4().to_string();
|
||||
for lang in languages.iter() {
|
||||
let result = Paragraph::new(data.clone(), lang.clone());
|
||||
assert_eq!(result.get(lang).unwrap(), &data);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn are_multiple_languages_stored() {
|
||||
let text = ["test", "テスト"];
|
||||
let languages = [Language::from_639_1("en").unwrap(), Language::from_639_1("ja").unwrap()];
|
||||
let mut paragraph = Paragraph::new(text[0].clone().to_string(), languages[0].clone());
|
||||
paragraph.add_translation(text[1].clone().to_string(), languages[1].clone());
|
||||
for i in 0..text.len() {
|
||||
assert_eq!(paragraph.get(&languages[i]).unwrap(), text[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct UniversalString {
|
||||
}
|
||||
|
||||
impl UniversalString {
|
||||
fn new() -> Self {
|
||||
Self {}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod universal_strings {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn are_initial_strings_empty() {
|
||||
UniversalString::new();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user