import { chain , Decoder , fields , fieldsAuto , number , string , tuple } from "../" ; test ( "decoding tuples" , ( ) => { type PointTuple = [ number , number ] ; const data = [ 50 , 325 ] ; const pointTupleDecoder1 = tuple < PointTuple > ( [ number , number ] ) ; expect ( pointTupleDecoder1 ( data ) ) . toMatchInlineSnapshot ( `
    Array [
      50,
      325,
    ]
  ` ) ; type Point = { x : number ; y : number ; } ; const pointDecoder1 = fields ( ( field ) : Point => ( { x : field ( "0" , number ) , y : field ( "1" , number ) , } ) , { allow : "array" } ) ; expect ( pointDecoder1 ( data ) ) . toMatchInlineSnapshot ( `
    Object {
      "x": 50,
      "y": 325,
    }
  ` ) ; const pointDecoder2 = chain ( tuple ( [ number , number ] ) , ( [ x , y ] ) => ( { x , y , } ) ) ; expect ( pointDecoder2 ( data ) ) . toEqual ( pointDecoder1 ( data ) ) ; expect ( tuple ( [ number , number , number , number ] ) ( [ 1 , 2 , 3 , 4 ] ) ) . toMatchInlineSnapshot ( `
      Array [
        1,
        2,
        3,
        4,
      ]
    ` ) ; const longTupleDecoder = fields ( ( field ) => ( { firstName : field ( "0" , string ) , lastName : field ( "1" , string ) , age : field ( "2" , number ) , description : field ( "3" , string ) , } ) , { allow : "array" } ) ; expect ( longTupleDecoder ( [ "John" , "Doe" , 30 , "Likes swimming." ] ) ) . toMatchInlineSnapshot ( `
      Object {
        "age": 30,
        "description": "Likes swimming.",
        "firstName": "John",
        "lastName": "Doe",
      }
    ` ) ; const obj = { x : 1 , y : 2 } ; const pointTupleDecoder2 = fields ( ( field ) : PointTuple => [ field ( "x" , number ) , field ( "y" , number ) ] ) ; expect ( pointTupleDecoder2 ( obj ) ) . toMatchInlineSnapshot ( `
    Array [
      1,
      2,
    ]
  ` ) ; const pointTupleDecoder3 = chain ( fieldsAuto ( { x : number , y : number , } ) , ( { x , y } ) => [ x , y ] ) ; expect ( pointTupleDecoder3 ( obj ) ) . toEqual ( pointTupleDecoder2 ( obj ) ) ; } ) ;