From ab186283d8b9b584285594c325cd7f2195e953a9 Mon Sep 17 00:00:00 2001 From: Hongbo Zhang Date: Sat, 21 Dec 2024 11:07:33 +0800 Subject: [PATCH] test: add initial coverage for `builtin/array_wbtest.mbt` remove unneeded check --- builtin/array.mbt | 3 --- builtin/array_wbtest.mbt | 18 ++++++++++++++++++ 2 files changed, 18 insertions(+), 3 deletions(-) create mode 100644 builtin/array_wbtest.mbt diff --git a/builtin/array.mbt b/builtin/array.mbt index f35717198..03a25f059 100644 --- a/builtin/array.mbt +++ b/builtin/array.mbt @@ -273,9 +273,6 @@ pub fn clear[T](self : Array[T]) -> Unit { /// assert_eq!(v2, [4, 5, 6]) /// ``` pub fn map[T, U](self : Array[T], f : (T) -> U) -> Array[U] { - if self.length() == 0 { - return [] - } let arr = Array::make_uninit(self.length()) for i, v in self { arr.unsafe_set(i, f(v)) diff --git a/builtin/array_wbtest.mbt b/builtin/array_wbtest.mbt new file mode 100644 index 000000000..1f965048f --- /dev/null +++ b/builtin/array_wbtest.mbt @@ -0,0 +1,18 @@ +// Copyright 2024 International Digital Economy Academy +// +// 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. + +test { + let empty : Array[Unit] = Array::make_uninit(0) + inspect!(empty, content="[]") +}