1// Copyright (c) 2021, Peter Ohler, All rights reserved.
2
3package sen_test
4
5import (
6	"testing"
7	"time"
8
9	"github.com/ohler55/ojg/sen"
10	"github.com/ohler55/ojg/tt"
11)
12
13func TestParserMongo(t *testing.T) {
14	p := sen.Parser{}
15	p.AddMongoFuncs()
16
17	src := `{
18  _id: ObjectId("60c02af61528f028e174d95c"),
19  date: ISODate("2021-06-29T02:03:04.005Z"),
20  date2: ISODate(1624932184005),
21  long: NumberLong("1234567890")
22  decimal: NumberDecimal("12345.67890")
23  badInt: NumberInt("1234zz")
24  badDecimal: NumberDecimal("1e2e3")
25}`
26	v := p.MustParse([]byte(src)).(map[string]interface{})
27
28	tt.Equal(t, "60c02af61528f028e174d95c", v["_id"])
29	tm := time.Unix(0, 1624932184005000000).UTC()
30	tt.Equal(t, tm, v["date"])
31	tt.Equal(t, tm, v["date2"])
32	tt.Equal(t, int64(1234567890), v["long"])
33	tt.Equal(t, 12345.67890, v["decimal"])
34}
35