package Ġio . github . z 4 kn 4 fe in . semver Ċ Ċ import Ġio . github . z 4 kn 4 fe in . semver . constraints . Constraint Ċ import Ġio . github . z 4 kn 4 fe in . semver . constraints . to Constraint Ċ import Ġkotlinx . serialization . Serializable Ċ import Ġkotlinx . serialization . decode FromString Ċ import Ġkotlinx . serialization . encode ToString Ċ import Ġkotlinx . serialization . json . Json Ċ import Ġkotlin . test . Test Ċ import Ġkotlin . test . assertEquals Ċ Ċ class ĠSerialization Tests Ġ{ ĊĠĠĠ Ġ@ Serializable ĊĠĠĠ Ġdata Ġclass ĠTo Serialize ( val Ġversion : ĠVersion ) ĊĊĠĠĠ Ġ@ Serializable ĊĠĠĠ Ġdata Ġclass ĠTo L oose Serialize ( ĊĠĠĠĠĠĠĠ Ġ@ Serializable ( with Ġ= ĠL oose Version Serializer :: class ) ĊĠĠĠĠĠĠĠ Ġval Ġversion : ĠVersion ĊĠĠĠ Ġ) ĊĊĠĠĠ Ġ@ Serializable ĊĠĠĠ Ġdata Ġclass ĠTo Constraint Serialize ( val Ġconstraint : ĠConstraint ) ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġtest Version Serialization () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġencoded Ġ= ĠJson . encode ToString (" 1 . 0 . 0 - alpha . 1 + build . 3 ". to Version ()) ĊĠĠĠĠĠĠĠ ĠassertEquals ("\" 1 . 0 . 0 - alpha . 1 + build . 3 \"", Ġencoded ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġtest Version Deserialization () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġdecoded Ġ= ĠJson . decode FromString < Version >(" \" 1 . 0 . 0 - alpha . 1 + build . 3 \" ") ĊĠĠĠĠĠĠĠ ĠassertEquals (" 1 . 0 . 0 - alpha . 1 + build . 3 ". to Version (), Ġdecoded ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġtest Member Version Serialization () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġobj Ġ= ĠTo Serialize ( version Ġ= Ġ" 1 . 0 . 0 - alpha . 1 + build . 3 ". to Version ()) ĊĠĠĠĠĠĠĠ Ġval Ġencoded Ġ= ĠJson . encode ToString ( obj ) ĊĠĠĠĠĠĠĠ ĠassertEquals ("{ \" version \":\" 1 . 0 . 0 - alpha . 1 + build . 3 \" }", Ġencoded ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġtest Member Version Deserialization () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġdecoded Ġ= ĠJson . decode FromString < To Serialize >(" {\" version \":\" 1 . 0 . 0 - alpha . 1 + build . 3 \" }") ĊĠĠĠĠĠĠĠ ĠassertEquals (" 1 . 0 . 0 - alpha . 1 + build . 3 ". to Version (), Ġdecoded . version ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġtest Member L oose Version Serialization () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġobj Ġ= ĠTo L oose Serialize ( version Ġ= Ġ" 1 - alpha . 1 + build . 3 ". to Version ( strict Ġ= Ġfalse )) ĊĠĠĠĠĠĠĠ Ġval Ġencoded Ġ= ĠJson . encode ToString ( obj ) ĊĠĠĠĠĠĠĠ ĠassertEquals ("{ \" version \":\" 1 . 0 . 0 - alpha . 1 + build . 3 \" }", Ġencoded ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġtest Member L oose Version Deserialization () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġdecoded Ġ= ĠJson . decode FromString < To L oose Serialize >(" {\" version \":\" 1 - alpha . 1 + build . 3 \" }") ĊĠĠĠĠĠĠĠ ĠassertEquals (" 1 - alpha . 1 + build . 3 ". to Version ( strict Ġ= Ġfalse ), Ġdecoded . version ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġtest Constraint Serialization () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġencoded Ġ= ĠJson . encode ToString ("> Ġ 1 . 2 . 3 ". to Constraint ()) ĊĠĠĠĠĠĠĠ ĠassertEquals ("\ "> 1 . 2 . 3 \"", Ġencoded ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġtest Constraint Deserialization () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġdecoded Ġ= ĠJson . decode FromString < Constraint > ("\ "> Ġ 1 . 2 . 3 \" ") ĊĠĠĠĠĠĠĠ ĠassertEquals ("> Ġ 1 . 2 . 3 ". to Constraint (), Ġdecoded ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġtest Member Constraint Serialization () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġobj Ġ= ĠTo Constraint Serialize ( constraint Ġ= Ġ"> Ġ 1 . 2 . 3 ". to Constraint ()) ĊĠĠĠĠĠĠĠ Ġval Ġencoded Ġ= ĠJson . encode ToString ( obj ) ĊĠĠĠĠĠĠĠ ĠassertEquals ("{ \" constraint \": \"> 1 . 2 . 3 \" }", Ġencoded ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġtest Member Constraint Deserialization () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġdecoded Ġ= ĠJson . decode FromString < To Constraint Serialize >(" {\" constraint \": \"> Ġ 1 . 2 . 3 \" }") ĊĠĠĠĠĠĠĠ ĠassertEquals ("> Ġ 1 . 2 . 3 ". to Constraint (), Ġdecoded . constraint ) ĊĠĠĠ Ġ} Ċ } Ċ