From f0fb6aeab118255266370121db79ab2a2fed88ad Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Sun, 13 Sep 2009 18:41:38 +0200 Subject: Add the fs::basic_path class --- tests/fs/makefile | 18 +++++++++++++ tests/fs/path/driver.cxx | 67 +++++++++++++++++++++++++++++++++++++++++++++ tests/fs/path/makefile | 70 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 155 insertions(+) create mode 100644 tests/fs/makefile create mode 100644 tests/fs/path/driver.cxx create mode 100644 tests/fs/path/makefile (limited to 'tests/fs') diff --git a/tests/fs/makefile b/tests/fs/makefile new file mode 100644 index 0000000..071c394 --- /dev/null +++ b/tests/fs/makefile @@ -0,0 +1,18 @@ +# file : tests/fs/makefile +# author : Boris Kolpackov +# copyright : Copyright (c) 2009 Code Synthesis Tools CC +# license : MIT; see accompanying LICENSE file + +include $(dir $(lastword $(MAKEFILE_LIST)))../../build/bootstrap.make + +tests := path + +default := $(out_base)/ +test := $(out_base)/.test +clean := $(out_base)/.clean + +$(default): $(addprefix $(out_base)/,$(addsuffix /,$(tests))) +$(test): $(addprefix $(out_base)/,$(addsuffix /.test,$(tests))) +$(clean): $(addprefix $(out_base)/,$(addsuffix /.clean,$(tests))) + +$(foreach t,$(tests),$(call import,$(src_base)/$t/makefile)) diff --git a/tests/fs/path/driver.cxx b/tests/fs/path/driver.cxx new file mode 100644 index 0000000..d758bde --- /dev/null +++ b/tests/fs/path/driver.cxx @@ -0,0 +1,67 @@ +// file : tests/fs/path/driver.cxx +// author : Boris Kolpackov +// copyright : Copyright (c) 2009 Code Synthesis Tools CC +// license : MIT; see accompanying LICENSE file + +#include + +#include + +using namespace cutl::fs; + +int +main () +{ + // Construction. + // + try + { + path (""); + assert (false); + } + catch (invalid_path const&) + { + } + + assert (path ("/").string () == "/"); + assert (path ("//").string () == "/"); + assert (path ("\\\\").string () == "/"); + assert (path ("/\\").string () == "/"); + assert (path ("C:").string () == "C:"); + assert (path ("C:\\").string () == "C:"); + assert (path ("/tmp/foo/").string () == "/tmp/foo"); + assert (path ("C:\\tmp\\foo\\").string () == "C:\\tmp\\foo"); + + // leaf + // + assert (path ("/").leaf ().string () == "/"); + assert (path ("C:").leaf ().string () == "C:"); + assert (path ("/tmp").leaf ().string () == "tmp"); + assert (path ("C:\\tmp").leaf ().string () == "tmp"); + assert (path ("//tmp").leaf ().string () == "tmp"); + assert (path ("C:\\\\tmp").leaf ().string () == "tmp"); + + // directory + // + assert (path ("/").directory ().string () == "/"); + assert (path ("C:").directory ().string () == "C:"); + assert (path ("/tmp").directory ().string () == "/"); + assert (path ("//tmp").directory ().string () == "/"); + assert (path ("C:\\tmp").directory ().string () == "C:"); + assert (path ("C:\\\\tmp").directory ().string () == "C:"); + + // base + // + assert (path ("/").base ().string () == "/"); + assert (path ("C:").base ().string () == "C:"); + assert (path ("/foo.txt").base ().string () == "/foo"); + assert (path ("C:\\foo.txt").base ().string () == "C:\\foo"); + assert (path (".txt").base ().string () == ".txt"); + assert (path ("/.txt").base ().string () == "/.txt"); + assert (path ("foo.txt.orig").base ().string () == "foo.txt"); + + // operator/ + // + assert ((path ("/") / path ("tmp")).string () == "/tmp"); + assert ((path ("foo") / path ("bar")).string () == "foo/bar"); +} diff --git a/tests/fs/path/makefile b/tests/fs/path/makefile new file mode 100644 index 0000000..55bf89d --- /dev/null +++ b/tests/fs/path/makefile @@ -0,0 +1,70 @@ +# file : tests/fs/path/makefile +# author : Boris Kolpackov +# copyright : Copyright (c) 2009 Code Synthesis Tools CC +# license : MIT; see accompanying LICENSE file + +include $(dir $(lastword $(MAKEFILE_LIST)))../../../build/bootstrap.make + +cxx_tun := driver.cxx + +# +# +cxx_obj := $(addprefix $(out_base)/,$(cxx_tun:.cxx=.o)) +cxx_od := $(cxx_obj:.o=.o.d) + +cutl.l := $(out_root)/cutl/cutl.l +cutl.l.cpp-options := $(out_root)/cutl/cutl.l.cpp-options + +driver := $(out_base)/driver +test := $(out_base)/.test +clean := $(out_base)/.clean + +# Build. +# +$(driver): $(cxx_obj) $(cutl.l) +$(cxx_obj) $(cxx_od): $(cutl.l.cpp-options) + + +$(call include-dep,$(cxx_od)) + + +# Alias for default target. +# +$(out_base)/: $(driver) + + +# Test. +# +$(test): $(driver) + $(call message,test $<,$<) + + +# Clean. +# +$(clean): \ + $(driver).o.clean \ + $(addsuffix .cxx.clean,$(cxx_obj)) \ + $(addsuffix .cxx.clean,$(cxx_od)) + + +# Generated .gitignore. +# +ifeq ($(out_base),$(src_base)) +$(driver): | $(out_base)/.gitignore + +$(out_base)/.gitignore: files := driver +$(clean): $(out_base)/.gitignore.clean + +$(call include,$(bld_root)/git/gitignore.make) +endif + + +# How to. +# +$(call include,$(bld_root)/cxx/o-e.make) +$(call include,$(bld_root)/cxx/cxx-o.make) +$(call include,$(bld_root)/cxx/cxx-d.make) + +# Dependencies. +# +$(call import,$(src_root)/cutl/makefile) -- cgit v1.1