diff options
| author | Yong He <yonghe@outlook.com> | 2020-07-06 11:58:14 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-07-06 11:58:14 -0700 |
| commit | cf62f13cdc8a7f21c78f03b097bff6edf09fdead (patch) | |
| tree | 6a08ddcd4dfe39976a7dec29164da4f7b87ddfda /tools | |
| parent | ffd0b9c9b06a22d886c77d777d9aa0cd1298d363 (diff) | |
ShortList<T> and core.natvis improvements. (#1430)
* ShortList<T> and core.natvis improvements.
* Fix gcc build.
* add `getBuffer()` accessor to `GetArrayViewResult`
Diffstat (limited to 'tools')
| -rw-r--r-- | tools/slang-test/slang-test.vcxproj | 1 | ||||
| -rw-r--r-- | tools/slang-test/slang-test.vcxproj.filters | 3 | ||||
| -rw-r--r-- | tools/slang-test/unit-test-short-list.cpp | 78 |
3 files changed, 82 insertions, 0 deletions
diff --git a/tools/slang-test/slang-test.vcxproj b/tools/slang-test/slang-test.vcxproj index bf79af2f1..d3e049222 100644 --- a/tools/slang-test/slang-test.vcxproj +++ b/tools/slang-test/slang-test.vcxproj @@ -182,6 +182,7 @@ <ClCompile Include="unit-test-memory-arena.cpp" /> <ClCompile Include="unit-test-path.cpp" /> <ClCompile Include="unit-test-riff.cpp" /> + <ClCompile Include="unit-test-short-list.cpp" /> <ClCompile Include="unit-test-string.cpp" /> </ItemGroup> <ItemGroup> diff --git a/tools/slang-test/slang-test.vcxproj.filters b/tools/slang-test/slang-test.vcxproj.filters index 824d92d26..70125e44d 100644 --- a/tools/slang-test/slang-test.vcxproj.filters +++ b/tools/slang-test/slang-test.vcxproj.filters @@ -68,5 +68,8 @@ <ClCompile Include="unit-test-string.cpp"> <Filter>Source Files</Filter> </ClCompile> + <ClCompile Include="unit-test-short-list.cpp"> + <Filter>Source Files</Filter> + </ClCompile> </ItemGroup> </Project>
\ No newline at end of file diff --git a/tools/slang-test/unit-test-short-list.cpp b/tools/slang-test/unit-test-short-list.cpp new file mode 100644 index 000000000..0559419bb --- /dev/null +++ b/tools/slang-test/unit-test-short-list.cpp @@ -0,0 +1,78 @@ +// unit-test-path.cpp + +#include "test-context.h" + +using namespace Slang; + +template<typename T> +static bool _checkArrayView(ArrayView<T> v0, ArrayView<T> v1) +{ + if (v0.getCount() != v1.getCount()) + return false; + for (Index i = 0; i < v0.getCount(); i++) + if (v0[i] != v1[i]) + return false; + return true; +} + +static void shortListUnitTest() +{ + { + ShortList<String, 4> shortList = { "a", "b", "c" }; + shortList.add("d"); + auto arrayView = shortList.getArrayView(); + SLANG_CHECK(arrayView.ownsStorage == false); + SLANG_CHECK(_checkArrayView(arrayView.arrayView, + List<String>{"a", "b", "c", "d"}.getArrayView())); + shortList.add("e"); + auto arrayView2 = shortList.getArrayView(); + SLANG_CHECK(arrayView2.ownsStorage == true); + SLANG_CHECK(_checkArrayView(arrayView2.arrayView, + List<String>{"a", "b", "c", "d", "e"}.getArrayView())); + auto arrayView3 = shortList.getArrayView(0, 2); + SLANG_CHECK(arrayView3.ownsStorage == false); + SLANG_CHECK(_checkArrayView(arrayView3.arrayView, + List<String>{"a", "b"}.getArrayView())); + auto arrayView4 = shortList.getArrayView(4, 1); + SLANG_CHECK(arrayView4.ownsStorage == false); + SLANG_CHECK(_checkArrayView(arrayView4.arrayView, + List<String>{"e"}.getArrayView())); + auto arrayView5 = shortList.getArrayView(2, 3); + SLANG_CHECK(arrayView5.ownsStorage == true); + SLANG_CHECK(_checkArrayView(arrayView5.arrayView, + List<String>{"c", "d", "e"}.getArrayView())); + + ShortList<String, 1> copy2; + ShortList<String, 2> copy1; + copy1 = shortList; + for (auto item : copy1) + copy2.add(item); + SLANG_CHECK(_checkArrayView(copy2.getArrayView().arrayView, + List<String>{"a", "b", "c", "d", "e"}.getArrayView())); + + SLANG_CHECK(copy2.indexOf("a") == 0); + SLANG_CHECK(copy2.indexOf("e") == 4); + + SLANG_CHECK(copy2.lastIndexOf("a") == 0); + SLANG_CHECK(copy2.lastIndexOf("e") == 4); + + copy2.compress(); + copy2.add("f"); + copy2.fastRemove("c"); + copy2.compress(); + SLANG_CHECK(_checkArrayView(copy2.getArrayView().arrayView, + List<String>{"a", "b", "f", "d", "e"}.getArrayView())); + + shortList.removeLast(); + shortList.removeLast(); + shortList.compress(); + SLANG_CHECK(_checkArrayView(shortList.getArrayView().arrayView, + List<String>{"a", "b", "c"}.getArrayView())); + shortList.add("d"); + shortList.add("e"); + SLANG_CHECK(_checkArrayView(shortList.getArrayView().arrayView, + List<String>{"a", "b", "c", "d", "e"}.getArrayView())); + } +} + +SLANG_UNIT_TEST("ShortList", shortListUnitTest); |
