|
3 | 3 | #include <scratchcpp/sprite.h> |
4 | 4 | #include <scratchcpp/stage.h> |
5 | 5 | #include <scratchcpp/variable.h> |
| 6 | +#include <scratchcpp/list.h> |
6 | 7 | #include <dev/engine/internal/llvm/llvmcodebuilder.h> |
7 | 8 | #include <gmock/gmock.h> |
8 | 9 | #include <targetmock.h> |
@@ -1899,6 +1900,80 @@ TEST_F(LLVMCodeBuilderTest, ReadVariable) |
1899 | 1900 | ASSERT_EQ(testing::internal::GetCapturedStdout(), expected); |
1900 | 1901 | } |
1901 | 1902 |
|
| 1903 | +TEST_F(LLVMCodeBuilderTest, ClearList) |
| 1904 | +{ |
| 1905 | + EngineMock engine; |
| 1906 | + Stage stage; |
| 1907 | + Sprite sprite; |
| 1908 | + sprite.setEngine(&engine); |
| 1909 | + EXPECT_CALL(engine, stage()).WillRepeatedly(Return(&stage)); |
| 1910 | + |
| 1911 | + std::unordered_map<List *, std::string> strings; |
| 1912 | + |
| 1913 | + auto globalList1 = std::make_shared<List>("", ""); |
| 1914 | + auto globalList2 = std::make_shared<List>("", ""); |
| 1915 | + auto globalList3 = std::make_shared<List>("", ""); |
| 1916 | + stage.addList(globalList1); |
| 1917 | + stage.addList(globalList2); |
| 1918 | + stage.addList(globalList3); |
| 1919 | + |
| 1920 | + auto localList1 = std::make_shared<List>("", ""); |
| 1921 | + auto localList2 = std::make_shared<List>("", ""); |
| 1922 | + auto localList3 = std::make_shared<List>("", ""); |
| 1923 | + sprite.addList(localList1); |
| 1924 | + sprite.addList(localList2); |
| 1925 | + sprite.addList(localList3); |
| 1926 | + |
| 1927 | + globalList1->append(1); |
| 1928 | + globalList1->append(2); |
| 1929 | + globalList1->append(3); |
| 1930 | + strings[globalList1.get()] = globalList1->toString(); |
| 1931 | + |
| 1932 | + globalList2->append("Lorem"); |
| 1933 | + globalList2->append("ipsum"); |
| 1934 | + globalList2->append(-4.52); |
| 1935 | + strings[globalList2.get()] = globalList2->toString(); |
| 1936 | + |
| 1937 | + globalList3->append(true); |
| 1938 | + globalList3->append(false); |
| 1939 | + globalList3->append(true); |
| 1940 | + strings[globalList3.get()] = globalList3->toString(); |
| 1941 | + |
| 1942 | + localList1->append("dolor"); |
| 1943 | + localList1->append("sit"); |
| 1944 | + localList1->append("amet"); |
| 1945 | + strings[localList1.get()] = localList1->toString(); |
| 1946 | + |
| 1947 | + localList2->append(10); |
| 1948 | + localList2->append(9.8); |
| 1949 | + localList2->append(true); |
| 1950 | + strings[localList2.get()] = localList2->toString(); |
| 1951 | + |
| 1952 | + localList3->append("test"); |
| 1953 | + localList3->append(1.2); |
| 1954 | + localList3->append(false); |
| 1955 | + strings[localList3.get()] = localList3->toString(); |
| 1956 | + |
| 1957 | + createBuilder(&sprite, true); |
| 1958 | + |
| 1959 | + m_builder->createListClear(globalList1.get()); |
| 1960 | + m_builder->createListClear(globalList3.get()); |
| 1961 | + m_builder->createListClear(localList1.get()); |
| 1962 | + m_builder->createListClear(localList2.get()); |
| 1963 | + |
| 1964 | + auto code = m_builder->finalize(); |
| 1965 | + auto ctx = code->createExecutionContext(&sprite); |
| 1966 | + code->run(ctx.get()); |
| 1967 | + |
| 1968 | + ASSERT_TRUE(globalList1->empty()); |
| 1969 | + ASSERT_EQ(globalList2->toString(), strings[globalList2.get()]); |
| 1970 | + ASSERT_TRUE(globalList3->empty()); |
| 1971 | + |
| 1972 | + ASSERT_TRUE(localList1->empty()); |
| 1973 | + ASSERT_TRUE(localList2->empty()); |
| 1974 | + ASSERT_EQ(localList3->toString(), strings[localList3.get()]); |
| 1975 | +} |
| 1976 | + |
1902 | 1977 | TEST_F(LLVMCodeBuilderTest, Yield) |
1903 | 1978 | { |
1904 | 1979 | auto build = [this]() { |
|
0 commit comments