2020-08-30 17:08:39 +02:00
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
|
|
KLayout Layout Viewer
|
2021-01-05 22:57:48 +01:00
|
|
|
Copyright (C) 2006-2021 Matthias Koefferlein
|
2020-08-30 17:08:39 +02:00
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "tlUnitTest.h"
|
|
|
|
|
#include "tlFileUtils.h"
|
2020-08-30 19:56:51 +02:00
|
|
|
#include "tlStream.h"
|
|
|
|
|
#include "tlInclude.h"
|
2020-08-30 17:08:39 +02:00
|
|
|
|
2020-09-20 01:07:39 +02:00
|
|
|
static std::string np (const std::string &s)
|
|
|
|
|
{
|
|
|
|
|
return tl::replaced (s, "\\", "/");
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-30 17:08:39 +02:00
|
|
|
TEST(1_simple)
|
|
|
|
|
{
|
2020-08-30 19:56:51 +02:00
|
|
|
std::string fn = tl::testsrc () + "/testdata/tl/x.txt";
|
2020-08-30 17:08:39 +02:00
|
|
|
|
|
|
|
|
std::string et;
|
2020-08-30 19:56:51 +02:00
|
|
|
tl::IncludeExpander ie = tl::IncludeExpander::expand (fn, et);
|
2020-08-30 17:08:39 +02:00
|
|
|
EXPECT_EQ (et, "A line\nAnother line\n");
|
|
|
|
|
EXPECT_EQ (ie.to_string (), fn);
|
2020-08-30 19:56:51 +02:00
|
|
|
EXPECT_EQ (tl::IncludeExpander::from_string (ie.to_string ()).to_string (), ie.to_string ());
|
2020-08-30 17:08:39 +02:00
|
|
|
|
|
|
|
|
EXPECT_EQ (ie.translate_to_original (2).first, fn);
|
|
|
|
|
EXPECT_EQ (ie.translate_to_original (2).second, 2);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(2_single_include)
|
|
|
|
|
{
|
2020-08-30 19:56:51 +02:00
|
|
|
std::string fn = tl::testsrc () + "/testdata/tl/x_inc1.txt";
|
2020-08-30 17:08:39 +02:00
|
|
|
|
|
|
|
|
std::string et;
|
2020-08-30 19:56:51 +02:00
|
|
|
tl::IncludeExpander ie = tl::IncludeExpander::expand (fn, tl::InputStream (fn).read_all (), et);
|
2020-08-30 17:08:39 +02:00
|
|
|
EXPECT_EQ (et, "A line\nincluded.1\nAnother line\n");
|
|
|
|
|
|
2020-09-20 01:07:39 +02:00
|
|
|
EXPECT_EQ (np (ie.to_string ()), np ("@1*" + tl::testsrc () + "/testdata/tl/x_inc1.txt*0;2*" + tl::testsrc () + "/testdata/tl/inc1.txt*-1;3*" + tl::testsrc () + "/testdata/tl/x_inc1.txt*0;"));
|
2020-08-30 19:56:51 +02:00
|
|
|
EXPECT_EQ (tl::IncludeExpander::from_string (ie.to_string ()).to_string (), ie.to_string ());
|
2020-08-30 17:08:39 +02:00
|
|
|
|
|
|
|
|
EXPECT_EQ (ie.translate_to_original (1).first, fn);
|
|
|
|
|
EXPECT_EQ (ie.translate_to_original (1).second, 1);
|
2020-09-20 01:07:39 +02:00
|
|
|
EXPECT_EQ (np (ie.translate_to_original (2).first), np (tl::testsrc () + "/testdata/tl/inc1.txt"));
|
2020-08-30 17:08:39 +02:00
|
|
|
EXPECT_EQ (ie.translate_to_original (2).second, 1);
|
|
|
|
|
EXPECT_EQ (ie.translate_to_original (3).first, fn);
|
|
|
|
|
EXPECT_EQ (ie.translate_to_original (3).second, 3);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(3_multi_include)
|
|
|
|
|
{
|
2020-08-30 19:56:51 +02:00
|
|
|
std::string fn = tl::testsrc () + "/testdata/tl/x_inc3.txt";
|
2020-08-30 17:08:39 +02:00
|
|
|
|
|
|
|
|
std::string et;
|
2020-08-30 19:56:51 +02:00
|
|
|
tl::IncludeExpander ie = tl::IncludeExpander::expand (fn, et);
|
2020-08-30 17:08:39 +02:00
|
|
|
EXPECT_EQ (et, "A line\ninclude.3a\nincluded.2a\nincluded.2b\ninclude.3b\nAnother line\n");
|
|
|
|
|
|
2020-08-30 19:56:51 +02:00
|
|
|
EXPECT_EQ (tl::IncludeExpander::from_string (ie.to_string ()).to_string (), ie.to_string ());
|
2020-08-30 17:08:39 +02:00
|
|
|
|
|
|
|
|
EXPECT_EQ (ie.translate_to_original (1).first, fn);
|
|
|
|
|
EXPECT_EQ (ie.translate_to_original (1).second, 1);
|
2020-09-20 01:07:39 +02:00
|
|
|
EXPECT_EQ (np (ie.translate_to_original (2).first), np (tl::testsrc () + "/testdata/tl/inc3.txt"));
|
2020-08-30 17:08:39 +02:00
|
|
|
EXPECT_EQ (ie.translate_to_original (2).second, 1);
|
2020-09-20 01:07:39 +02:00
|
|
|
EXPECT_EQ (np (ie.translate_to_original (3).first), np (tl::testsrc () + "/testdata/tl/inc2.txt"));
|
2020-08-30 17:08:39 +02:00
|
|
|
EXPECT_EQ (ie.translate_to_original (3).second, 1);
|
2020-09-20 01:07:39 +02:00
|
|
|
EXPECT_EQ (np (ie.translate_to_original (5).first), np (tl::testsrc () + "/testdata/tl/inc3.txt"));
|
2020-08-30 17:08:39 +02:00
|
|
|
EXPECT_EQ (ie.translate_to_original (5).second, 3);
|
|
|
|
|
EXPECT_EQ (ie.translate_to_original (6).first, fn);
|
|
|
|
|
EXPECT_EQ (ie.translate_to_original (6).second, 3);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(4_multi_include_interpolate)
|
|
|
|
|
{
|
2020-08-30 19:56:51 +02:00
|
|
|
std::string fn = tl::testsrc () + "/testdata/tl/x_inc3_ip.txt";
|
2020-08-30 17:08:39 +02:00
|
|
|
|
|
|
|
|
std::string et;
|
2020-08-30 19:56:51 +02:00
|
|
|
tl::IncludeExpander ie = tl::IncludeExpander::expand (fn, et);
|
2020-08-30 17:08:39 +02:00
|
|
|
EXPECT_EQ (et, "A line\ninclude.3a\nincluded.2a\nincluded.2b\ninclude.3b\nAnother line\n");
|
|
|
|
|
|
2020-08-30 19:56:51 +02:00
|
|
|
EXPECT_EQ (tl::IncludeExpander::from_string (ie.to_string ()).to_string (), ie.to_string ());
|
2020-08-30 17:08:39 +02:00
|
|
|
|
|
|
|
|
EXPECT_EQ (ie.translate_to_original (1).first, fn);
|
|
|
|
|
EXPECT_EQ (ie.translate_to_original (1).second, 1);
|
2020-09-20 01:07:39 +02:00
|
|
|
EXPECT_EQ (np (ie.translate_to_original (2).first), np (tl::testsrc () + "/testdata/tl/inc3.txt"));
|
2020-08-30 17:08:39 +02:00
|
|
|
EXPECT_EQ (ie.translate_to_original (2).second, 1);
|
2020-09-20 01:07:39 +02:00
|
|
|
EXPECT_EQ (np (ie.translate_to_original (3).first), np (tl::testsrc () + "/testdata/tl/inc2.txt"));
|
2020-08-30 17:08:39 +02:00
|
|
|
EXPECT_EQ (ie.translate_to_original (3).second, 1);
|
2020-09-20 01:07:39 +02:00
|
|
|
EXPECT_EQ (np (ie.translate_to_original (5).first), np (tl::testsrc () + "/testdata/tl/inc3.txt"));
|
2020-08-30 17:08:39 +02:00
|
|
|
EXPECT_EQ (ie.translate_to_original (5).second, 3);
|
|
|
|
|
EXPECT_EQ (ie.translate_to_original (6).first, fn);
|
|
|
|
|
EXPECT_EQ (ie.translate_to_original (6).second, 3);
|
|
|
|
|
}
|
|
|
|
|
|