Skip to content

Commit

Permalink
start schema work
Browse files Browse the repository at this point in the history
  • Loading branch information
hgrsd committed Mar 29, 2024
1 parent 74cc73a commit 59be8a5
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 0 deletions.
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

65 changes: 65 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#[derive(PartialEq, Eq, Debug)]
pub enum SchemaState {
Unknown,
Null,
String,
Number,
Boolean,
Array(Box<SchemaState>),
Object {
required: Vec<(String, SchemaState)>,
optional: Vec<(String, SchemaState)>,
},
}

pub fn merge_state(current_state: SchemaState, new_state: SchemaState) -> SchemaState {
SchemaState::Unknown
}

#[cfg(test)]
mod test {
mod merge {
use crate::{merge_state, SchemaState};

#[test]
fn anything_merged_with_unknown_yields_unknown() {
assert_eq!(
merge_state(SchemaState::Unknown, SchemaState::Unknown),
SchemaState::Unknown
);
assert_eq!(
merge_state(SchemaState::Null, SchemaState::Unknown),
SchemaState::Unknown
);
assert_eq!(
merge_state(SchemaState::String, SchemaState::Unknown),
SchemaState::Unknown
);
assert_eq!(
merge_state(SchemaState::Number, SchemaState::Unknown),
SchemaState::Unknown
);
assert_eq!(
merge_state(SchemaState::Boolean, SchemaState::Unknown),
SchemaState::Unknown
);
assert_eq!(
merge_state(
SchemaState::Array(Box::new(SchemaState::Number)),
SchemaState::Unknown
),
SchemaState::Unknown
);
assert_eq!(
merge_state(
SchemaState::Object {
required: vec![("foo".to_owned(), SchemaState::Boolean)],
optional: Vec::new()
},
SchemaState::Unknown
),
SchemaState::Unknown
);
}
}
}

0 comments on commit 59be8a5

Please sign in to comment.