Add KV tests to confirm keys are being serialised the right way (#2166)

This commit is contained in:
Przemyslaw Hugh Kaznowski 2023-07-06 19:51:31 +01:00 committed by GitHub
parent b33223562a
commit 8e5f2a85cc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
35 changed files with 308 additions and 116 deletions

View file

@ -58,7 +58,20 @@ mod tests {
"test", "test",
); );
let enc = Az::encode(&val).unwrap(); let enc = Az::encode(&val).unwrap();
assert_eq!(enc, b"/*ns\0*db\0!aztest\0");
let dec = Az::decode(&enc).unwrap(); let dec = Az::decode(&enc).unwrap();
assert_eq!(val, dec); assert_eq!(val, dec);
} }
#[test]
fn prefix() {
let val = super::prefix("namespace", "database");
assert_eq!(val, b"/*namespace\0*database\0!az\0");
}
#[test]
fn suffix() {
let val = super::suffix("namespace", "database");
assert_eq!(val, b"/*namespace\0*database\0!az\xff");
}
} }

View file

@ -41,18 +41,21 @@ impl<'a> Bc<'a> {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
#[test] #[test]
fn key() { fn key() {
use super::*; use super::*;
#[rustfmt::skip] #[rustfmt::skip]
let val = Bc::new( let val = Bc::new(
"test", "testns",
"test", "testdb",
"test", "testtb",
"test", "testix",
7 7
); );
let enc = Bc::encode(&val).unwrap(); let enc = Bc::encode(&val).unwrap();
assert_eq!(enc, b"/*testns\0*testdb\0*testtb\0!bctestix\0*\0\0\0\0\0\0\0\x07");
let dec = Bc::decode(&enc).unwrap(); let dec = Bc::decode(&enc).unwrap();
assert_eq!(val, dec); assert_eq!(val, dec);
} }

View file

@ -52,13 +52,19 @@ mod tests {
use super::*; use super::*;
#[rustfmt::skip] #[rustfmt::skip]
let val = Bd::new( let val = Bd::new(
"test", "testns",
"test", "testdb",
"test", "testtb",
"test", "testix",
Some(7) Some(7)
); );
let enc = Bd::encode(&val).unwrap(); let enc = Bd::encode(&val).unwrap();
assert_eq!(
enc,
b"/*testns\0*testdb\0*testtb\0!bdtestix\0*\
\x01\
\0\0\0\0\0\0\0\x07"
);
let dec = Bd::decode(&enc).unwrap(); let dec = Bd::decode(&enc).unwrap();
assert_eq!(val, dec); assert_eq!(val, dec);
} }

View file

@ -57,14 +57,21 @@ mod tests {
fn key() { fn key() {
#[rustfmt::skip] #[rustfmt::skip]
let val = Bf::new( let val = Bf::new(
"test", "testns",
"test", "testdb",
"test", "testtb",
"test", "testix",
1, 7,
2 13
); );
let enc = Bf::encode(&val).unwrap(); let enc = Bf::encode(&val).unwrap();
assert_eq!(
enc,
b"/*testns\0*testdb\0*testtb\0!bftestix\0*\
\0\0\0\0\0\0\0\x07\
\0\0\0\0\0\0\0\x0d"
);
let dec = Bf::decode(&enc).unwrap(); let dec = Bf::decode(&enc).unwrap();
assert_eq!(val, dec); assert_eq!(val, dec);
} }

View file

@ -46,13 +46,19 @@ mod tests {
use super::*; use super::*;
#[rustfmt::skip] #[rustfmt::skip]
let val = Bi::new( let val = Bi::new(
"test", "testns",
"test", "testdb",
"test", "testtb",
"test", "testix",
7 7
); );
let enc = Bi::encode(&val).unwrap(); let enc = Bi::encode(&val).unwrap();
assert_eq!(
enc,
b"/*testns\0*testdb\0*testtb\0!bitestix\0*\
\0\0\0\0\0\0\0\x07"
);
let dec = Bi::decode(&enc).unwrap(); let dec = Bi::decode(&enc).unwrap();
assert_eq!(val, dec); assert_eq!(val, dec);
} }

View file

@ -46,13 +46,15 @@ mod tests {
use super::*; use super::*;
#[rustfmt::skip] #[rustfmt::skip]
let val = Bk::new( let val = Bk::new(
"test", "testns",
"test", "testdb",
"test", "testtb",
"test", "testix",
7 7
); );
let enc = Bk::encode(&val).unwrap(); let enc = Bk::encode(&val).unwrap();
assert_eq!(enc, b"/*testns\0*testdb\0*testtb\0!bktestix\0*\0\0\0\0\0\0\0\x07");
let dec = Bk::decode(&enc).unwrap(); let dec = Bk::decode(&enc).unwrap();
assert_eq!(val, dec); assert_eq!(val, dec);
} }

View file

@ -52,13 +52,20 @@ mod tests {
use super::*; use super::*;
#[rustfmt::skip] #[rustfmt::skip]
let val = Bl::new( let val = Bl::new(
"test", "testns",
"test", "testdb",
"test", "testtb",
"test", "testix",
Some(7) Some(7)
); );
let enc = Bl::encode(&val).unwrap(); let enc = Bl::encode(&val).unwrap();
assert_eq!(
enc,
b"/*testns\0*testdb\0*testtb\0!bltestix\0*\
\x01\
\0\0\0\0\0\0\0\x07"
);
let dec = Bl::decode(&enc).unwrap(); let dec = Bl::decode(&enc).unwrap();
assert_eq!(val, dec); assert_eq!(val, dec);
} }

View file

@ -56,13 +56,18 @@ mod tests {
use super::*; use super::*;
#[rustfmt::skip] #[rustfmt::skip]
let val = Bo::new( let val = Bo::new(
"test", "testns",
"test", "testdb",
"test", "testtb",
"test", "testix",
1,2 1,2
); );
let enc = Bo::encode(&val).unwrap(); let enc = Bo::encode(&val).unwrap();
assert_eq!(
enc,
b"/*testns\0*testdb\0*testtb\0!botestix\0*\0\0\0\0\0\0\0\x01\0\0\0\0\0\0\0\x02"
);
let dec = Bo::decode(&enc).unwrap(); let dec = Bo::decode(&enc).unwrap();
assert_eq!(val, dec); assert_eq!(val, dec);
} }

View file

@ -52,13 +52,20 @@ mod tests {
use super::*; use super::*;
#[rustfmt::skip] #[rustfmt::skip]
let val = Bp::new( let val = Bp::new(
"test", "testns",
"test", "testdb",
"test", "testtb",
"test", "testix",
Some(7) Some(7)
); );
let enc = Bp::encode(&val).unwrap(); let enc = Bp::encode(&val).unwrap();
assert_eq!(
enc,
b"/*testns\0*testdb\0*testtb\0!bptestix\0*\
\x01\
\0\0\0\0\0\0\0\x07"
);
let dec = Bp::decode(&enc).unwrap(); let dec = Bp::decode(&enc).unwrap();
assert_eq!(val, dec); assert_eq!(val, dec);
} }

View file

@ -41,12 +41,14 @@ mod tests {
use super::*; use super::*;
#[rustfmt::skip] #[rustfmt::skip]
let val = Bs::new( let val = Bs::new(
"test", "testns",
"test", "testdb",
"test", "testtb",
"test", "testix",
); );
let enc = Bs::encode(&val).unwrap(); let enc = Bs::encode(&val).unwrap();
assert_eq!(enc, b"/*testns\0*testdb\0*testtb\0!bstestix\0");
let dec = Bs::decode(&enc).unwrap(); let dec = Bs::decode(&enc).unwrap();
assert_eq!(val, dec); assert_eq!(val, dec);
} }

View file

@ -52,13 +52,19 @@ mod tests {
use super::*; use super::*;
#[rustfmt::skip] #[rustfmt::skip]
let val = Bt::new( let val = Bt::new(
"test", "testns",
"test", "testdb",
"test", "testtb",
"test", "testix",
Some(7) Some(7)
); );
let enc = Bt::encode(&val).unwrap(); let enc = Bt::encode(&val).unwrap();
assert_eq!(
enc,
b"/*testns\0*testdb\0*testtb\0!bttestix\0*\
\x01\
\0\0\0\0\0\0\0\x07"
);
let dec = Bt::decode(&enc).unwrap(); let dec = Bt::decode(&enc).unwrap();
assert_eq!(val, dec); assert_eq!(val, dec);
} }

View file

@ -46,13 +46,15 @@ mod tests {
use super::*; use super::*;
#[rustfmt::skip] #[rustfmt::skip]
let val = Bu::new( let val = Bu::new(
"test", "testns",
"test", "testdb",
"test", "testtb",
"test", "testix",
7 7
); );
let enc = Bu::encode(&val).unwrap(); let enc = Bu::encode(&val).unwrap();
assert_eq!(enc, b"/*testns\0*testdb\0*testtb\0!butestix\0*\0\0\0\0\0\0\0\x07");
let dec = Bu::decode(&enc).unwrap(); let dec = Bu::decode(&enc).unwrap();
assert_eq!(val, dec); assert_eq!(val, dec);
} }

View file

@ -33,10 +33,12 @@ mod tests {
use super::*; use super::*;
#[rustfmt::skip] #[rustfmt::skip]
let val = Database::new( let val = Database::new(
"test", "testns",
"test", "testdb",
); );
let enc = Database::encode(&val).unwrap(); let enc = Database::encode(&val).unwrap();
assert_eq!(enc, b"/*testns\0*testdb\0");
let dec = Database::decode(&enc).unwrap(); let dec = Database::decode(&enc).unwrap();
assert_eq!(val, dec); assert_eq!(val, dec);
} }

View file

@ -49,11 +49,25 @@ mod tests {
use super::*; use super::*;
#[rustfmt::skip] #[rustfmt::skip]
let val = Db::new( let val = Db::new(
"test", "testns",
"test", "testdb",
); );
let enc = Db::encode(&val).unwrap(); let enc = Db::encode(&val).unwrap();
assert_eq!(enc, b"/*testns\0!dbtestdb\0");
let dec = Db::decode(&enc).unwrap(); let dec = Db::decode(&enc).unwrap();
assert_eq!(val, dec); assert_eq!(val, dec);
} }
#[test]
fn test_prefix() {
let val = super::prefix("testns");
assert_eq!(val, b"/*testns\0!db\0")
}
#[test]
fn test_suffix() {
let val = super::suffix("testns");
assert_eq!(val, b"/*testns\0!db\xff")
}
} }

View file

@ -53,11 +53,13 @@ mod tests {
use super::*; use super::*;
#[rustfmt::skip] #[rustfmt::skip]
let val = Dl::new( let val = Dl::new(
"test", "testns",
"test", "testdb",
"test", "testdl",
); );
let enc = Dl::encode(&val).unwrap(); let enc = Dl::encode(&val).unwrap();
assert_eq!(enc, b"/*testns\0*testdb\0!dltestdl\0");
let dec = Dl::decode(&enc).unwrap(); let dec = Dl::decode(&enc).unwrap();
assert_eq!(val, dec); assert_eq!(val, dec);
} }

View file

@ -53,12 +53,26 @@ mod tests {
use super::*; use super::*;
#[rustfmt::skip] #[rustfmt::skip]
let val = Dt::new( let val = Dt::new(
"test", "testns",
"test", "testdb",
"test", "testtk",
); );
let enc = Dt::encode(&val).unwrap(); let enc = Dt::encode(&val).unwrap();
assert_eq!(enc, b"/*testns\x00*testdb\x00!dttesttk\x00");
let dec = Dt::decode(&enc).unwrap(); let dec = Dt::decode(&enc).unwrap();
assert_eq!(val, dec); assert_eq!(val, dec);
} }
#[test]
fn test_prefix() {
let val = super::prefix("testns", "testdb");
assert_eq!(val, b"/*testns\0*testdb\0!dt\0");
}
#[test]
fn test_suffix() {
let val = super::suffix("testns", "testdb");
assert_eq!(val, b"/*testns\0*testdb\0!dt\xff");
}
} }

View file

@ -57,13 +57,27 @@ mod tests {
use super::*; use super::*;
#[rustfmt::skip] #[rustfmt::skip]
let val = Ev::new( let val = Ev::new(
"test", "testns",
"test", "testdb",
"test", "testtb",
"test", "testev",
); );
let enc = Ev::encode(&val).unwrap(); let enc = Ev::encode(&val).unwrap();
assert_eq!(enc, b"/*testns\x00*testdb\x00*testtb\x00!evtestev\x00");
let dec = Ev::decode(&enc).unwrap(); let dec = Ev::decode(&enc).unwrap();
assert_eq!(val, dec); assert_eq!(val, dec);
} }
#[test]
fn test_prefix() {
let val = super::prefix("testns", "testdb", "testtb");
assert_eq!(val, b"/*testns\0*testdb\0*testtb\0!ev\0");
}
#[test]
fn test_suffix() {
let val = super::suffix("testns", "testdb", "testtb");
assert_eq!(val, b"/*testns\0*testdb\0*testtb\0!ev\xff");
}
} }

View file

@ -53,12 +53,25 @@ mod tests {
use super::*; use super::*;
#[rustfmt::skip] #[rustfmt::skip]
let val = Fc::new( let val = Fc::new(
"test", "testns",
"test", "testdb",
"test", "testfc",
); );
let enc = Fc::encode(&val).unwrap(); let enc = Fc::encode(&val).unwrap();
assert_eq!(enc, b"/*testns\x00*testdb\x00!fntestfc\x00");
let dec = Fc::decode(&enc).unwrap(); let dec = Fc::decode(&enc).unwrap();
assert_eq!(val, dec); assert_eq!(val, dec);
} }
#[test]
fn test_prefix() {
let val = super::prefix("testns", "testdb");
assert_eq!(val, b"/*testns\0*testdb\0!fn\0");
}
#[test]
fn test_suffix() {
let val = super::suffix("testns", "testdb");
assert_eq!(val, b"/*testns\0*testdb\0!fn\xff");
}
} }

View file

@ -57,13 +57,27 @@ mod tests {
use super::*; use super::*;
#[rustfmt::skip] #[rustfmt::skip]
let val = Fd::new( let val = Fd::new(
"test", "testns",
"test", "testdb",
"test", "testtb",
"test", "testfd",
); );
let enc = Fd::encode(&val).unwrap(); let enc = Fd::encode(&val).unwrap();
assert_eq!(enc, b"/*testns\x00*testdb\x00*testtb\x00!fdtestfd\x00");
let dec = Fd::decode(&enc).unwrap(); let dec = Fd::decode(&enc).unwrap();
assert_eq!(val, dec); assert_eq!(val, dec);
} }
#[test]
fn test_prefix() {
let val = super::prefix("testns", "testdb", "testtb");
assert_eq!(val, b"/*testns\0*testdb\0*testtb\0!fd\0");
}
#[test]
fn test_suffix() {
let val = super::suffix("testns", "testdb", "testtb");
assert_eq!(val, b"/*testns\0*testdb\0*testtb\0!fd\xff");
}
} }

View file

@ -57,13 +57,27 @@ mod tests {
use super::*; use super::*;
#[rustfmt::skip] #[rustfmt::skip]
let val = Ft::new( let val = Ft::new(
"test", "testns",
"test", "testdb",
"test", "testtb",
"test", "testft",
); );
let enc = Ft::encode(&val).unwrap(); let enc = Ft::encode(&val).unwrap();
assert_eq!(enc, b"/*testns\x00*testdb\x00*testtb\x00!fttestft\x00");
let dec = Ft::decode(&enc).unwrap(); let dec = Ft::decode(&enc).unwrap();
assert_eq!(val, dec); assert_eq!(val, dec);
} }
#[test]
fn test_prefix() {
let val = super::prefix("testns", "testdb", "testtb");
assert_eq!(val, b"/*testns\0*testdb\0*testtb\0!ft\0");
}
#[test]
fn test_suffix() {
let val = super::suffix("testns", "testdb", "testtb");
assert_eq!(val, b"/*testns\0*testdb\0*testtb\0!ft\xff");
}
} }

View file

@ -188,14 +188,19 @@ mod tests {
let fk = Thing::parse("other:test"); let fk = Thing::parse("other:test");
#[rustfmt::skip] #[rustfmt::skip]
let val = Graph::new( let val = Graph::new(
"test", "testns",
"test", "testdb",
"test", "testtb",
"test".into(), "testid".into(),
Dir::Out, Dir::Out,
&fk, &fk,
); );
let enc = Graph::encode(&val).unwrap(); let enc = Graph::encode(&val).unwrap();
assert_eq!(
enc,
b"/*testns\0*testdb\0*testtb\x00~\0\0\0\x01testid\0\0\0\0\x01other\0\0\0\0\x01test\0"
);
let dec = Graph::decode(&enc).unwrap(); let dec = Graph::decode(&enc).unwrap();
assert_eq!(val, dec); assert_eq!(val, dec);
} }

View file

@ -146,14 +146,19 @@ mod tests {
use super::*; use super::*;
#[rustfmt::skip] #[rustfmt::skip]
let val = Index::new( let val = Index::new(
"test", "testns",
"test", "testdb",
"test", "testtb",
"test", "testix",
vec!["test"].into(), vec!["testfd1", "testfd2"].into(),
Some("test".into()), Some("testid".into()),
); );
let enc = Index::encode(&val).unwrap(); let enc = Index::encode(&val).unwrap();
assert_eq!(
enc,
b"/*testns\0*testdb\0*testtb\0\xa4testix\0\0\0\0\x04testfd1\0\0\0\0\x04testfd2\0\x01\x01\0\0\0\x01testid\0"
);
let dec = Index::decode(&enc).unwrap(); let dec = Index::decode(&enc).unwrap();
assert_eq!(val, dec); assert_eq!(val, dec);
} }

View file

@ -57,12 +57,14 @@ mod tests {
use super::*; use super::*;
#[rustfmt::skip] #[rustfmt::skip]
let val = Ix::new( let val = Ix::new(
"test", "testns",
"test", "testdb",
"test", "testtb",
"test", "testix",
); );
let enc = Ix::encode(&val).unwrap(); let enc = Ix::encode(&val).unwrap();
assert_eq!(enc, b"/*testns\0*testdb\0*testtb\0!ixtestix\0");
let dec = Ix::decode(&enc).unwrap(); let dec = Ix::decode(&enc).unwrap();
assert_eq!(val, dec); assert_eq!(val, dec);
} }

View file

@ -32,6 +32,8 @@ mod tests {
#[rustfmt::skip] #[rustfmt::skip]
let val = Kv::new(); let val = Kv::new();
let enc = Kv::encode(&val).unwrap(); let enc = Kv::encode(&val).unwrap();
assert_eq!(enc, b"/");
let dec = Kv::decode(&enc).unwrap(); let dec = Kv::decode(&enc).unwrap();
assert_eq!(val, dec); assert_eq!(val, dec);
} }

View file

@ -29,9 +29,11 @@ mod tests {
use super::*; use super::*;
#[rustfmt::skip] #[rustfmt::skip]
let val = Namespace::new( let val = Namespace::new(
"test", "testns",
); );
let enc = Namespace::encode(&val).unwrap(); let enc = Namespace::encode(&val).unwrap();
assert_eq!(enc, b"/*testns\0");
let dec = Namespace::decode(&enc).unwrap(); let dec = Namespace::decode(&enc).unwrap();
assert_eq!(val, dec); assert_eq!(val, dec);
} }

View file

@ -49,10 +49,12 @@ mod tests {
use super::*; use super::*;
#[rustfmt::skip] #[rustfmt::skip]
let val = Nl::new( let val = Nl::new(
"test", "testns",
"test", "testus",
); );
let enc = Nl::encode(&val).unwrap(); let enc = Nl::encode(&val).unwrap();
assert_eq!(enc, b"/*testns\0!nltestus\0");
let dec = Nl::decode(&enc).unwrap(); let dec = Nl::decode(&enc).unwrap();
assert_eq!(val, dec); assert_eq!(val, dec);
} }

View file

@ -45,9 +45,11 @@ mod tests {
use super::*; use super::*;
#[rustfmt::skip] #[rustfmt::skip]
let val = Ns::new( let val = Ns::new(
"test", "testns",
); );
let enc = Ns::encode(&val).unwrap(); let enc = Ns::encode(&val).unwrap();
assert_eq!(enc, b"/!nstestns\0");
let dec = Ns::decode(&enc).unwrap(); let dec = Ns::decode(&enc).unwrap();
assert_eq!(val, dec); assert_eq!(val, dec);
} }

View file

@ -49,10 +49,11 @@ mod tests {
use super::*; use super::*;
#[rustfmt::skip] #[rustfmt::skip]
let val = Nt::new( let val = Nt::new(
"test", "testns",
"test", "testtk",
); );
let enc = Nt::encode(&val).unwrap(); let enc = Nt::encode(&val).unwrap();
assert_eq!(enc, b"/*testns\0!nttesttk\0");
let dec = Nt::decode(&enc).unwrap(); let dec = Nt::decode(&enc).unwrap();
assert_eq!(val, dec); assert_eq!(val, dec);
} }

View file

@ -53,11 +53,13 @@ mod tests {
use super::*; use super::*;
#[rustfmt::skip] #[rustfmt::skip]
let val = Pa::new( let val = Pa::new(
"test", "testns",
"test", "testdb",
"test", "testpa",
); );
let enc = Pa::encode(&val).unwrap(); let enc = Pa::encode(&val).unwrap();
assert_eq!(enc, b"/*testns\0*testdb\0!patestpa\0");
let dec = Pa::decode(&enc).unwrap(); let dec = Pa::decode(&enc).unwrap();
assert_eq!(val, dec); assert_eq!(val, dec);
} }

View file

@ -53,11 +53,13 @@ mod tests {
use super::*; use super::*;
#[rustfmt::skip] #[rustfmt::skip]
let val = Sc::new( let val = Sc::new(
"test", "testns",
"test", "testdb",
"test", "testsc",
); );
let enc = Sc::encode(&val).unwrap(); let enc = Sc::encode(&val).unwrap();
assert_eq!(enc, b"/*testns\0*testdb\0!sctestsc\0");
let dec = Sc::decode(&enc).unwrap(); let dec = Sc::decode(&enc).unwrap();
assert_eq!(val, dec); assert_eq!(val, dec);
} }

View file

@ -38,11 +38,13 @@ mod tests {
use super::*; use super::*;
#[rustfmt::skip] #[rustfmt::skip]
let val = Scope::new( let val = Scope::new(
"test", "testns",
"test", "testdb",
"test", "testsc",
); );
let enc = Scope::encode(&val).unwrap(); let enc = Scope::encode(&val).unwrap();
assert_eq!(enc, b"/*testns\0*testdb\0\xb1testsc\0");
let dec = Scope::decode(&enc).unwrap(); let dec = Scope::decode(&enc).unwrap();
assert_eq!(val, dec); assert_eq!(val, dec);
} }

View file

@ -58,12 +58,14 @@ mod tests {
use super::*; use super::*;
#[rustfmt::skip] #[rustfmt::skip]
let val = St::new( let val = St::new(
"test", "testns",
"test", "testdb",
"test", "testsc",
"test", "testtk",
); );
let enc = St::encode(&val).unwrap(); let enc = St::encode(&val).unwrap();
assert_eq!(enc, b"/*testns\0*testdb\0\xb1testsc\0!sttesttk\0");
let dec = St::decode(&enc).unwrap(); let dec = St::decode(&enc).unwrap();
assert_eq!(val, dec); assert_eq!(val, dec);
} }

View file

@ -37,11 +37,13 @@ mod tests {
use super::*; use super::*;
#[rustfmt::skip] #[rustfmt::skip]
let val = Table::new( let val = Table::new(
"test", "testns",
"test", "testdb",
"test", "testtb",
); );
let enc = Table::encode(&val).unwrap(); let enc = Table::encode(&val).unwrap();
assert_eq!(enc, b"/*testns\0*testdb\0*testtb\0");
let dec = Table::decode(&enc).unwrap(); let dec = Table::decode(&enc).unwrap();
assert_eq!(val, dec); assert_eq!(val, dec);
} }

View file

@ -53,11 +53,13 @@ mod tests {
use super::*; use super::*;
#[rustfmt::skip] #[rustfmt::skip]
let val = Tb::new( let val = Tb::new(
"test", "testns",
"test", "testdb",
"test", "testtb",
); );
let enc = Tb::encode(&val).unwrap(); let enc = Tb::encode(&val).unwrap();
assert_eq!(enc, b"/*testns\0*testdb\0!tbtesttb\0");
let dec = Tb::decode(&enc).unwrap(); let dec = Tb::decode(&enc).unwrap();
assert_eq!(val, dec); assert_eq!(val, dec);
} }

View file

@ -54,12 +54,14 @@ mod tests {
use super::*; use super::*;
#[rustfmt::skip] #[rustfmt::skip]
let val = Thing::new( let val = Thing::new(
"test", "testns",
"test", "testdb",
"test", "testtb",
"test".into(), "testid".into(),
); );
let enc = Thing::encode(&val).unwrap(); let enc = Thing::encode(&val).unwrap();
assert_eq!(enc, b"/*testns\0*testdb\0*testtb\0*\0\0\0\x01testid\0");
let dec = Thing::decode(&enc).unwrap(); let dec = Thing::decode(&enc).unwrap();
assert_eq!(val, dec); assert_eq!(val, dec);
} }
@ -69,16 +71,20 @@ mod tests {
// //
let id1 = "['test']"; let id1 = "['test']";
let (_, id1) = crate::sql::id::id(id1).expect("Failed to parse the ID"); let (_, id1) = crate::sql::id::id(id1).expect("Failed to parse the ID");
let val = Thing::new("test", "test", "test", id1); let val = Thing::new("testns", "testdb", "testtb", id1);
let enc = Thing::encode(&val).unwrap(); let enc = Thing::encode(&val).unwrap();
assert_eq!(enc, b"/*testns\0*testdb\0*testtb\0*\0\0\0\x02\0\0\0\x04test\0\x01");
let dec = Thing::decode(&enc).unwrap(); let dec = Thing::decode(&enc).unwrap();
assert_eq!(val, dec); assert_eq!(val, dec);
println!("---"); println!("---");
// //
let id2 = "['f8e238f2-e734-47b8-9a16-476b291bd78a']"; let id2 = "['f8e238f2-e734-47b8-9a16-476b291bd78a']";
let (_, id2) = crate::sql::id::id(id2).expect("Failed to parse the ID"); let (_, id2) = crate::sql::id::id(id2).expect("Failed to parse the ID");
let val = Thing::new("test", "test", "test", id2); let val = Thing::new("testns", "testdb", "testtb", id2);
let enc = Thing::encode(&val).unwrap(); let enc = Thing::encode(&val).unwrap();
assert_eq!(enc, b"/*testns\0*testdb\0*testtb\0*\0\0\0\x02\0\0\0\x07\xf8\xe2\x38\xf2\xe7\x34\x47\xb8\x9a\x16\x47\x6b\x29\x1b\xd7\x8a\x01");
let dec = Thing::decode(&enc).unwrap(); let dec = Thing::decode(&enc).unwrap();
assert_eq!(val, dec); assert_eq!(val, dec);
println!("---"); println!("---");