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 chrono::prelude::*;
|
||||||
|
use isolang::Language;
|
||||||
use std::{
|
use std::{
|
||||||
cmp::Ordering,
|
cmp::Ordering,
|
||||||
|
collections::HashMap,
|
||||||
ops::{Add, AddAssign},
|
ops::{Add, AddAssign},
|
||||||
time::Duration,
|
time::Duration,
|
||||||
};
|
};
|
||||||
@@ -13,7 +15,6 @@ pub enum Field {
|
|||||||
Duration(Duration),
|
Duration(Duration),
|
||||||
Integer(i128),
|
Integer(i128),
|
||||||
None,
|
None,
|
||||||
Revision(Revision),
|
|
||||||
StaticString(String),
|
StaticString(String),
|
||||||
Uuid(Uuid),
|
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 {
|
impl From<String> for Field {
|
||||||
fn from(value: String) -> Self {
|
fn from(value: String) -> Self {
|
||||||
Self::StaticString(value)
|
Self::StaticString(value)
|
||||||
@@ -121,7 +116,6 @@ impl PartialOrd for Field {
|
|||||||
(Self::DateTime(d1), Self::DateTime(d2)) => d1.partial_cmp(d2),
|
(Self::DateTime(d1), Self::DateTime(d2)) => d1.partial_cmp(d2),
|
||||||
(Self::Duration(d1), Self::Duration(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::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::StaticString(d1), Self::StaticString(d2)) => d1.partial_cmp(d2),
|
||||||
(Self::Uuid(d1), Self::Uuid(d2)) => d1.partial_cmp(d2),
|
(Self::Uuid(d1), Self::Uuid(d2)) => d1.partial_cmp(d2),
|
||||||
(_, _) => None,
|
(_, _) => None,
|
||||||
@@ -277,7 +271,6 @@ pub enum FieldType {
|
|||||||
Duration,
|
Duration,
|
||||||
Integer,
|
Integer,
|
||||||
None,
|
None,
|
||||||
Revision,
|
|
||||||
StaticString,
|
StaticString,
|
||||||
Uuid,
|
Uuid,
|
||||||
}
|
}
|
||||||
@@ -290,7 +283,6 @@ impl FieldType {
|
|||||||
FieldType::Duration => Duration::from_secs(0).into(),
|
FieldType::Duration => Duration::from_secs(0).into(),
|
||||||
FieldType::Integer => 0.into(),
|
FieldType::Integer => 0.into(),
|
||||||
FieldType::None => Field::None,
|
FieldType::None => Field::None,
|
||||||
FieldType::Revision => Revision::new().into(),
|
|
||||||
FieldType::StaticString => "".into(),
|
FieldType::StaticString => "".into(),
|
||||||
FieldType::Uuid => Uuid::new_v4().into(),
|
FieldType::Uuid => Uuid::new_v4().into(),
|
||||||
}
|
}
|
||||||
@@ -305,7 +297,6 @@ impl From<&Field> for FieldType {
|
|||||||
Field::Duration(_) => Self::Duration,
|
Field::Duration(_) => Self::Duration,
|
||||||
Field::Integer(_) => Self::Integer,
|
Field::Integer(_) => Self::Integer,
|
||||||
Field::None => Self::None,
|
Field::None => Self::None,
|
||||||
Field::Revision(_) => Self::Revision,
|
|
||||||
Field::StaticString(_) => Self::StaticString,
|
Field::StaticString(_) => Self::StaticString,
|
||||||
Field::Uuid(_) => Self::Uuid,
|
Field::Uuid(_) => Self::Uuid,
|
||||||
}
|
}
|
||||||
@@ -348,26 +339,69 @@ mod fieldtypes {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
|
struct Paragraph {
|
||||||
struct Revision;
|
data: HashMap<Language, String>,
|
||||||
|
|
||||||
impl Revision {
|
|
||||||
fn new() -> Self {
|
|
||||||
Self {}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn revision(&self) -> isize {
|
impl Paragraph {
|
||||||
0
|
fn new(string: String, lang: Language) -> Self {
|
||||||
|
let mut data = HashMap::new();
|
||||||
|
data.insert(lang, string);
|
||||||
|
Self {
|
||||||
|
data: data,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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)]
|
#[cfg(test)]
|
||||||
mod revisions {
|
mod paragraphs {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn can_create_empty_revision() {
|
fn does_paragraph_store_language_information() {
|
||||||
let rev = Revision::new();
|
let languages = [Language::from_639_1("en").unwrap(), Language::from_639_1("ja").unwrap()];
|
||||||
assert_eq!(rev.revision(), 0);
|
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