Skip to content
This repository was archived by the owner on Oct 12, 2022. It is now read-only.
/ druntime Public archive
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion test/stdcpp/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ all:
clean:

else
all: $(addprefix $(ROOT)/,$(addsuffix .done,$(TESTS)))
all: $(addprefix $(ROOT)/,$(addsuffix .done,$(TESTS))) $(ROOT)/string_view

$(ROOT)/%.done : $(ROOT)/%
@echo Testing $*
Expand All @@ -24,6 +24,11 @@ $(ROOT)/%: $(SRC)/%_test.d $(SRC)/%.cpp
$(QUIET)$(CXX) $(CXXFLAGS) -c -o $(ROOT)/$*_cpp.o $(SRC)/$*.cpp
$(QUIET)$(DMD) $(DFLAGS) -main -unittest -of$@ $< $(ROOT)/$*_cpp.o

$(ROOT)/string_view: $(SRC)/string_view_test.d $(SRC)/string_view.cpp
mkdir -p $(dir $@)
$(QUIET)$(CXX) $(CXXFLAGS) -std=c++17 -c -o $(ROOT)/string_view_cpp.o $(SRC)/string_view.cpp
$(QUIET)$(DMD) $(DFLAGS) -main -unittest -of$@ $< $(ROOT)/string_view_cpp.o

clean:
rm -rf $(GENERATED)
endif
8 changes: 8 additions & 0 deletions test/stdcpp/src/string_view.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#include <string_view>
#include <assert.h>

int fromC_val(std::string_view);
int fromC_ref(const std::string_view&);
std::string_view getFromD();

int sumOfElements_ref(const std::string_view& str)
{
Expand All @@ -15,3 +17,9 @@ int sumOfElements_val(std::string_view str)
{
return sumOfElements_ref(str) + fromC_ref(str) + fromC_val(str);
}

std::string_view getFromC()
{
assert(getFromD().compare("I'm from D!") == 0);
return std::string_view("I'm from C++!");
}
10 changes: 10 additions & 0 deletions test/stdcpp/src/string_view_test.d
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ unittest
assert(str2.length == 0);
assert(str2.empty == true);
assert(str2[] == []);

assert(getFromC() == "I'm from C++!");

return 0;
}


Expand All @@ -24,6 +28,7 @@ extern(C++):
// test the ABI for calls to C++
int sumOfElements_val(string_view);
int sumOfElements_ref(ref const(string_view));
string_view getFromC();

// test the ABI for calls from C++
int fromC_val(string_view str)
Expand All @@ -48,3 +53,8 @@ int fromC_ref(ref const(string_view) str)
r += e;
return r;
}

string_view getFromD()
{
return string_view("I'm from D!");
}