/* * Copyright 2021 ByteDance Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package ast import ( `fmt` `strconv` `testing` ) func TestIterator(t *testing.T) { var data []int var v1 = "" var v2 = "" loop := _DEFAULT_NODE_CAP+1 for i:=0;i= int64(ai.Len()) { t.Fatal(i) } i++ } root, err = NewParser(str).Parse() if err != 0 { t.Fatal(err) } mi := root.Get("object").Properties() i = int64(0) for mi.HasNext() { v := &Pair{} if !mi.Next(v) { t.Fatalf("no next") } if i < int64(loop) &&( v.Value.Int64() != i ||v.Key != fmt.Sprintf("k%d", i)) { t.Fatalf("exp:%v, got:%v", i, v.Value.Interface()) } if i != int64(mi.Pos())-1 || i >= int64(mi.Len()) { t.Fatal(i) } i++ } } func BenchmarkArrays(b *testing.B) { for i:=0;i