import { strict as assert } from "assert" ; import { Marker , ReferenceType , TextSegment } from "@fluidframework/merge-tree" ; import { SubSequence } from "../sharedSequence" ; const segmentTypes = [ { ctor : ( ) => new TextSegment ( "text" ) , fromJSON : TextSegment . fromJSONObject , name : "TextSegment" } , { ctor : ( ) => new Marker ( ReferenceType . Simple ) , fromJSON : Marker . fromJSONObject , name : "Marker" } , { ctor : ( ) => new SubSequence ( [ 0 ] ) , fromJSON : SubSequence . fromJSONObject , name : "SubSequence" } , ] ; describe ( "Segment Marshalling" , ( ) => { for ( const { name , ctor , fromJSON } of segmentTypes ) { describe ( name , ( ) => { describe ( "to/from spec" , ( ) => { it ( "unannotated" , ( ) => { const expected = ctor ( ) ; const spec = expected . toJSONObject ( ) ; const actual = fromJSON ( spec ) ; assert . deepStrictEqual ( expected , actual ) ; } ) ; it ( "annotated" , ( ) => { const expected = ctor ( ) ; expected . addProperties ( { hasProperties : true , numProperties : 2 } ) ; const spec = expected . toJSONObject ( ) ; const actual = fromJSON ( spec ) ; assert . deepStrictEqual ( expected , actual ) ; } ) ; it ( "returns 'undefined' for unrecognized JSON spec" , ( ) => { for ( const unrecognized of [ { } , Symbol ( ) , NaN , undefined , null , true , false ] ) { assert . strictEqual ( undefined , fromJSON ( unrecognized ) ) ; } } ) ; } ) ; } ) ; } } ) ;