content: {-# LANGUAGE DataKinds #-}
  {-# LANGUAGE TypeApplications #-}
  {-# LANGUAGE OverloadedLists #-}
  {-# LANGUAGE OverloadedStrings #-}
  
  module LensSpec (spec, main) where
  
  import Control.Lens
  import Data.Proxy
  import Data.Schematic
  import Data.Vinyl
  import Test.Hspec
  
  
  type ArraySchema = 'SchemaArray '[ 'AEq 1] ('SchemaNumber '[ 'NGt 10])
  
  type ArrayField = '("foo", ArraySchema)
  
  type FieldsSchema =
    '[ '("bar", 'SchemaOptional ('SchemaText '[ 'TEnum '["foo", "bar"]])), ArrayField]
  
  arrayData :: JsonRepr ArraySchema
  arrayData = ReprArray [ReprNumber 13]
  
  arrayField :: FieldRepr ArrayField
  arrayField = FieldRepr arrayData
  
  objectData :: Rec FieldRepr FieldsSchema
  objectData = FieldRepr (ReprOptional (Just (ReprText "foo")))
    :& FieldRepr arrayData
    :& RNil
  
  type BigRecord = Rec FieldRepr
    '[ '("f1", 'SchemaNumber '[])
    ,  '("f2", 'SchemaNumber '[])
    ,  '("f3", 'SchemaNumber '[])
    ,  '("f4", 'SchemaNumber '[])
    ,  '("f5", 'SchemaNumber '[])
    ,  '("f6", 'SchemaNumber '[])
    ,  '("f7", 'SchemaNumber '[])
    ,  '("f8", 'SchemaNumber '[])
    ,  '("f9", 'SchemaNumber '[])
    ,  '("f10", 'SchemaNumber '[])
    ,  '("f11", 'SchemaNumber '[])
    ,  '("f12", 'SchemaNumber '[])
    ,  '("f13", 'SchemaNumber '[])
    ,  '("f14", 'SchemaNumber '[])
    ,  '("f15", 'SchemaNumber '[])
    ,  '("f16", 'SchemaNumber '[])
    ,  '("f17", 'SchemaNumber '[])
    ,  '("f18", 'SchemaNumber '[])
    ,  '("f19", 'SchemaNumber '[])
    ,  '("f20", 'SchemaNumber '[])
    ,  '("f21", 'SchemaNumber '[])
    ,  '("f22", 'SchemaNumber '[])
    ,  '("f23", 'SchemaNumber '[])
    ,  '("f24", 'SchemaNumber '[])
    ,  '("f25", 'SchemaNumber '[])
    ,  '("f26", 'SchemaNumber '[])
    ,  '("f27", 'SchemaNumber '[])
    ,  '("f28", 'SchemaNumber '[])
    ,  '("f29", 'SchemaNumber '[])
    ,  '("f30", 'SchemaNumber '[])
    ,  '("f31", 'SchemaNumber '[])
    ,  '("f32", 'SchemaNumber '[])
    ,  '("f33", 'SchemaNumber '[])
    ,  '("f34", 'SchemaNumber '[])
    ,  '("f35", 'SchemaNumber '[])
    ,  '("f36", 'SchemaNumber '[])
    ,  '("f37", 'SchemaNumber '[])
    ,  '("f38", 'SchemaNumber '[])
    ,  '("f39", 'SchemaNumber '[])
    ,  '("f40", 'SchemaNumber '[])
    ,  '("f41", 'SchemaNumber '[])
    ,  '("f42", 'SchemaNumber '[])
    ,  '("f43", 'SchemaNumber '[])
    ,  '("f44", 'SchemaNumber '[])
    ,  '("f45", 'SchemaNumber '[])
    ,  '("f46", 'SchemaNumber '[])
    ,  '("f47", 'SchemaNumber '[])
    ,  '("f48", 'SchemaNumber '[])
    ,  '("f49", 'SchemaNumber '[])
    ,  '("f50", 'SchemaNumber '[])
    ,  '("f51", 'SchemaNumber '[])
    ,  '("f52", 'SchemaNumber '[])
    ,  '("f53", 'SchemaNumber '[])
    ,  '("f54", 'SchemaNumber '[])
    ,  '("f55", 'SchemaNumber '[])
    ,  '("f56", 'SchemaNumber '[])
    ,  '("f57", 'SchemaNumber '[])
    ,  '("f58", 'SchemaNumber '[])
    ,  '("f59", 'SchemaNumber '[])
    ,  '("f60", 'SchemaNumber '[])
    ,  '("f61", 'SchemaNumber '[])
    ,  '("f62", 'SchemaNumber '[])
    ,  '("f63", 'SchemaNumber '[])
    ,  '("f64", 'SchemaNumber '[])
    ,  '("f65", 'SchemaNumber '[])
    ,  '("f66", 'SchemaNumber '[])
    ,  '("f67", 'SchemaNumber '[])
    ,  '("f68", 'SchemaNumber '[])
    ,  '("f69", 'SchemaNumber '[])
    ,  '("f70", 'SchemaNumber '[])
    ,  '("f71", 'SchemaNumber '[])
    ,  '("f72", 'SchemaNumber '[])
    ,  '("f73", 'SchemaNumber '[])
    ,  '("f74", 'SchemaNumber '[])
    ,  '("f75", 'SchemaNumber '[])
    ,  '("f76", 'SchemaNumber '[])
    ,  '("f77", 'SchemaNumber '[])
    ,  '("f78", 'SchemaNumber '[])
    ,  '("f79", 'SchemaNumber '[])
    ,  '("f80", 'SchemaNumber '[])
    ,  '("f81", 'SchemaNumber '[])
    ,  '("f82", 'SchemaNumber '[])
    ,  '("f83", 'SchemaNumber '[])
    ,  '("f84", 'SchemaNumber '[])
    ,  '("f85", 'SchemaNumber '[])
    ,  '("f86", 'SchemaNumber '[])
    ,  '("f87", 'SchemaNumber '[])
    ,  '("f88", 'SchemaNumber '[])
    ,  '("f89", 'SchemaNumber '[])
    ,  '("f90", 'SchemaNumber '[])
    ,  '("f91", 'SchemaNumber '[])
    ,  '("f92", 'SchemaNumber '[])
    ,  '("f93", 'SchemaNumber '[])
    ,  '("f94", 'SchemaNumber '[])
    ,  '("f95", 'SchemaNumber '[])
    ,  '("f96", 'SchemaNumber '[])
    ,  '("f97", 'SchemaNumber '[])
    ,  '("f98", 'SchemaNumber '[])
    ,  '("f99", 'SchemaNumber '[])
    ,  '("f100", 'SchemaNumber '[])
    ,  '("f101", 'SchemaNumber '[])
    ,  '("f102", 'SchemaNumber '[])
    ,  '("f103", 'SchemaNumber '[])
    ,  '("f104", 'SchemaNumber '[])
    ,  '("f105", 'SchemaNumber '[])
    ,  '("f106", 'SchemaNumber '[])
    ,  '("f107", 'SchemaNumber '[])
    ,  '("f108", 'SchemaNumber '[])
    ,  '("f109", 'SchemaNumber '[])
    ,  '("f110", 'SchemaNumber '[])
    ,  '("f111", 'SchemaNumber '[])
    ,  '("f112", 'SchemaNumber '[])
    ,  '("f113", 'SchemaNumber '[])
    ,  '("f114", 'SchemaNumber '[])
    ,  '("f115", 'SchemaNumber '[])
    ,  '("f116", 'SchemaNumber '[])
    ,  '("f117", 'SchemaNumber '[])
    ,  '("f118", 'SchemaNumber '[])
    ,  '("f119", 'SchemaNumber '[])
    ,  '("f120", 'SchemaNumber '[])
    ,  '("f121", 'SchemaNumber '[])
    ,  '("f122", 'SchemaNumber '[])
    ,  '("f123", 'SchemaNumber '[])
    ,  '("f124", 'SchemaNumber '[])
    ,  '("f125", 'SchemaNumber '[])
    ,  '("f126", 'SchemaNumber '[])
    ,  '("f127", 'SchemaNumber '[])
    ,  '("f128", 'SchemaNumber '[])
    ,  '("f129", 'SchemaNumber '[])
    ,  '("f130", 'SchemaNumber '[])
     ]
  
  _bigRecord :: BigRecord
  _bigRecord =
       FieldRepr (ReprNumber 1)
    :& FieldRepr (ReprNumber 2)
    :& FieldRepr (ReprNumber 3)
    :& FieldRepr (ReprNumber 4)
    :& FieldRepr (ReprNumber 5)
    :& FieldRepr (ReprNumber 6)
    :& FieldRepr (ReprNumber 7)
    :& FieldRepr (ReprNumber 8)
    :& FieldRepr (ReprNumber 9)
    :& FieldRepr (ReprNumber 10)
    :& FieldRepr (ReprNumber 11)
    :& FieldRepr (ReprNumber 12)
    :& FieldRepr (ReprNumber 13)
    :& FieldRepr (ReprNumber 14)
    :& FieldRepr (ReprNumber 15)
    :& FieldRepr (ReprNumber 16)
    :& FieldRepr (ReprNumber 17)
    :& FieldRepr (ReprNumber 18)
    :& FieldRepr (ReprNumber 19)
    :& FieldRepr (ReprNumber 20)
    :& FieldRepr (ReprNumber 21)
    :& FieldRepr (ReprNumber 22)
    :& FieldRepr (ReprNumber 23)
    :& FieldRepr (ReprNumber 24)
    :& FieldRepr (ReprNumber 25)
    :& FieldRepr (ReprNumber 26)
    :& FieldRepr (ReprNumber 27)
    :& FieldRepr (ReprNumber 28)
    :& FieldRepr (ReprNumber 29)
    :& FieldRepr (ReprNumber 30)
    :& FieldRepr (ReprNumber 31)
    :& FieldRepr (ReprNumber 32)
    :& FieldRepr (ReprNumber 33)
    :& FieldRepr (ReprNumber 34)
    :& FieldRepr (ReprNumber 35)
    :& FieldRepr (ReprNumber 36)
    :& FieldRepr (ReprNumber 37)
    :& FieldRepr (ReprNumber 38)
    :& FieldRepr (ReprNumber 39)
    :& FieldRepr (ReprNumber 40)
    :& FieldRepr (ReprNumber 41)
    :& FieldRepr (ReprNumber 42)
    :& FieldRepr (ReprNumber 43)
    :& FieldRepr (ReprNumber 44)
    :& FieldRepr (ReprNumber 45)
    :& FieldRepr (ReprNumber 46)
    :& FieldRepr (ReprNumber 47)
    :& FieldRepr (ReprNumber 48)
    :& FieldRepr (ReprNumber 49)
    :& FieldRepr (ReprNumber 50)
    :& FieldRepr (ReprNumber 51)
    :& FieldRepr (ReprNumber 52)
    :& FieldRepr (ReprNumber 53)
    :& FieldRepr (ReprNumber 54)
    :& FieldRepr (ReprNumber 55)
    :& FieldRepr (ReprNumber 56)
    :& FieldRepr (ReprNumber 57)
    :& FieldRepr (ReprNumber 58)
    :& FieldRepr (ReprNumber 59)
    :& FieldRepr (ReprNumber 60)
    :& FieldRepr (ReprNumber 61)
    :& FieldRepr (ReprNumber 62)
    :& FieldRepr (ReprNumber 63)
    :& FieldRepr (ReprNumber 64)
    :& FieldRepr (ReprNumber 65)
    :& FieldRepr (ReprNumber 66)
    :& FieldRepr (ReprNumber 67)
    :& FieldRepr (ReprNumber 68)
    :& FieldRepr (ReprNumber 69)
    :& FieldRepr (ReprNumber 70)
    :& FieldRepr (ReprNumber 71)
    :& FieldRepr (ReprNumber 72)
    :& FieldRepr (ReprNumber 73)
    :& FieldRepr (ReprNumber 74)
    :& FieldRepr (ReprNumber 75)
    :& FieldRepr (ReprNumber 76)
    :& FieldRepr (ReprNumber 77)
    :& FieldRepr (ReprNumber 78)
    :& FieldRepr (ReprNumber 79)
    :& FieldRepr (ReprNumber 80)
    :& FieldRepr (ReprNumber 81)
    :& FieldRepr (ReprNumber 82)
    :& FieldRepr (ReprNumber 83)
    :& FieldRepr (ReprNumber 84)
    :& FieldRepr (ReprNumber 85)
    :& FieldRepr (ReprNumber 86)
    :& FieldRepr (ReprNumber 87)
    :& FieldRepr (ReprNumber 88)
    :& FieldRepr (ReprNumber 89)
    :& FieldRepr (ReprNumber 90)
    :& FieldRepr (ReprNumber 91)
    :& FieldRepr (ReprNumber 92)
    :& FieldRepr (ReprNumber 93)
    :& FieldRepr (ReprNumber 94)
    :& FieldRepr (ReprNumber 95)
    :& FieldRepr (ReprNumber 96)
    :& FieldRepr (ReprNumber 97)
    :& FieldRepr (ReprNumber 98)
    :& FieldRepr (ReprNumber 99)
    :& FieldRepr (ReprNumber 100)
    :& FieldRepr (ReprNumber 101)
    :& FieldRepr (ReprNumber 102)
    :& FieldRepr (ReprNumber 103)
    :& FieldRepr (ReprNumber 104)
    :& FieldRepr (ReprNumber 105)
    :& FieldRepr (ReprNumber 106)
    :& FieldRepr (ReprNumber 107)
    :& FieldRepr (ReprNumber 108)
    :& FieldRepr (ReprNumber 109)
    :& FieldRepr (ReprNumber 110)
    :& FieldRepr (ReprNumber 111)
    :& FieldRepr (ReprNumber 112)
    :& FieldRepr (ReprNumber 113)
    :& FieldRepr (ReprNumber 114)
    :& FieldRepr (ReprNumber 115)
    :& FieldRepr (ReprNumber 116)
    :& FieldRepr (ReprNumber 117)
    :& FieldRepr (ReprNumber 118)
    :& FieldRepr (ReprNumber 119)
    :& FieldRepr (ReprNumber 120)
    :& FieldRepr (ReprNumber 121)
    :& FieldRepr (ReprNumber 122)
    :& FieldRepr (ReprNumber 123)
    :& FieldRepr (ReprNumber 124)
    :& FieldRepr (ReprNumber 125)
    :& FieldRepr (ReprNumber 126)
    :& FieldRepr (ReprNumber 127)
    :& FieldRepr (ReprNumber 128)
    :& FieldRepr (ReprNumber 129)
    :& FieldRepr (ReprNumber 130)
    :& RNil
  
  spec :: Spec
  spec = do
    let
      newFooVal = FieldRepr $ ReprArray [ReprNumber 15]
      fooProxy  = Proxy @"foo"
    it "gets the field from an object" $ do
      fget @"foo" objectData `shouldBe` arrayField
    it "sets the object field" $ do
      fget @"foo" (fput newFooVal objectData) `shouldBe` newFooVal
  
    describe "(using lens library) " $ do
      it "get the field from an object" $ do
        objectData ^. flens @"foo" `shouldBe` arrayField
      it "sets the object field" $ do
        set (flens @"foo") newFooVal objectData ^. flens @"foo"
          `shouldBe` newFooVal
  
  main :: IO ()
  main = hspec spec
  