From 7a74d71a951e5fbe25d8609b2855ebc352d51a69 Mon Sep 17 00:00:00 2001
From: Nina Dzugasova <dzugasova.nina@gmail.com>
Date: Mon, 5 Nov 2018 16:56:24 +0100
Subject: [PATCH] More StringExamples and added FileNameTest

---
 src/Examples/StringExample.cpp | 48 ++++++++++++++++++++-------
 src/Examples/StringExample.out | 16 +++++++--
 src/TNL/String.h               |  2 +-
 src/UnitTests/FileNameTest.cpp | 59 ++++++++++++++++++++++++++++------
 src/UnitTests/StringTest.cpp   |  2 ++
 5 files changed, 104 insertions(+), 23 deletions(-)

diff --git a/src/Examples/StringExample.cpp b/src/Examples/StringExample.cpp
index 1297f521fa..f33da1392c 100644
--- a/src/Examples/StringExample.cpp
+++ b/src/Examples/StringExample.cpp
@@ -81,32 +81,58 @@ int main()
     String g;
     g = 'y';
     cout << "g:" << g << endl;
-    
+
     String h( "x" );
     h += g;
     cout << "h:" << h << endl;
-    
+
     String i;
     i = 'a' + 'b';
     cout << "i:" << i << endl;
-    
+
     String letter1( "u" );
     if ( letter1 == "u" ) cout << "Letters are the same." << endl;
-    
+
     String letter2( "v" );
     if ( letter2 != "w" ) cout << "Letters are different." << endl;
-    
-    //Cast to bool operators
+
+    // Cast to bool operators
     String full( "string" );
     if ( full ) cout << "String is not empty." << endl;
-    
+
     String empty;
     if ( !empty ) cout << "String is empty." << endl;
-    
-    //replace
+
+    // replace
     String phrase( "Hakuna matata" );
     new_phrase = phrase.replace( "a", "u", 2 );
     cout << "new_phrase:" << new_phrase << endl;
-    
-    
+
+    // strip
+    String names("       Josh Martin   John  Marley Charles   ");
+    better_names = names.strip();
+    cout << "better_names:" << better_names << endl;
+
+    // split
+    String dates("3/4/2005;8/7/2011;11/12/2019");
+    list_dates = dates.split( list, ';' );
+    cout << "list_dates:" << list_dates << endl;
+
+    // save
+    String("Header").save(my-file.tnl); // saves "Header" into file my-file.tnl
+
+    // load
+    String strg;
+    strg.load(my-file.tnl);
+    cout << "strg:" << strg << endl;
+
+    // get line
+    std::stringstream text;
+    text << "Hello!" << std::endl;
+    text << "What's up?" << std::endl;
+
+    String str;
+    str.getLine( text );
+    cout << "str:" << str << endl;
+
 }
diff --git a/src/Examples/StringExample.out b/src/Examples/StringExample.out
index 4bc752b22d..87170b8a9f 100644
--- a/src/Examples/StringExample.out
+++ b/src/Examples/StringExample.out
@@ -32,9 +32,21 @@ i: ab
 Letters are the same.
 Letters are different.
 
-//Cast to bool operators
+// Cast to bool operators
 String is not empty.
 String is empty.
         
-//replace
+// replace
 new_phrase: Hukunu matata
+
+// strip
+list_dates: 3/4/2005 8/7/2011 11/12/2019
+
+// save
+true
+
+// load
+strg: Header
+
+// get line
+str: Hello!
\ No newline at end of file
diff --git a/src/TNL/String.h b/src/TNL/String.h
index 52d77bdcd9..6b77d12f4c 100644
--- a/src/TNL/String.h
+++ b/src/TNL/String.h
@@ -31,7 +31,7 @@ String convertToString( const T& value );
 /// \par Example
 /// \include StringExample.cpp
 /// \par Output
-/// \include StringOutput.cpp
+/// \include StringExample.out
 class String
 {
    public:
diff --git a/src/UnitTests/FileNameTest.cpp b/src/UnitTests/FileNameTest.cpp
index 3f71be1460..38192af053 100644
--- a/src/UnitTests/FileNameTest.cpp
+++ b/src/UnitTests/FileNameTest.cpp
@@ -15,22 +15,63 @@
 #endif
 
 #include <TNL/FileName.h>
+#include <TNL/String.h>
 
 using namespace TNL;
 
 #ifdef HAVE_GTEST 
 TEST( FileNameTest, Constructor )
 {
-   /*String str1( "string1" );
-   String str2( "xxxstring2", 3 );
-   String str3( "string3xxx", 0, 3 );
-   String str4( "xxxstring4xxx", 3, 3 );
-
-   EXPECT_EQ( strcmp( str1.getString(), "string1" ), 0 );
-   EXPECT_EQ( strcmp( str2.getString(), "string2" ), 0 );
-   EXPECT_EQ( strcmp( str3.getString(), "string3" ), 0 );
-   EXPECT_EQ( strcmp( str4.getString(), "string4" ), 0 );*/
+    FileName fname;
+
+    EXPECT_EQ( strcmp( fname.getFileName(), "00000." ), 0 );
+}
+
+TEST( FileNameTest, Base )
+{
+    FileName fname;
+    fname.setFileNameBase("name");
+
+    EXPECT_EQ( strcmp( fname.getFileName(), "name00000." ), 0 );
+}
+
+/*TEST( FileNameTest, Extension )
+{
+    FileName fname;
+    fname.setExtension("tnl");
+
+    EXPECT_EQ( strcmp( fname.getFileName(), "00000.tnl" ), 0 );
+}*/
+
+/*TEST( FileNameTest, Index )
+{
+    FileName fname1;
+    FileName fname2;
+    fname1.setIndex(1);
+    fname2.setIndex(50);
+
+    EXPECT_EQ( strcmp( fname1.getFileName(), "00001." ), 0 );
+    EXPECT_EQ( strcmp( fname2.getFileName(), "00050." ), 0 );
+}*/
+
+/*TEST( FileNameTest, DigitsCount )
+{
+    FileName fname;
+    fname.setDigitsCount(4);
+
+    EXPECT_EQ( strcmp( fname.getFileName(), "0000." ), 0 );
 }
+
+TEST( FileNameTest, AllTogether )
+{
+    FileName fname;
+    fname.setFileNameBase("name");
+    fname.setExtension("tnl");
+    fname.setIndex(8);
+    fname.setDigitsCount(3);
+
+    EXPECT_EQ( strcmp( fname.getFileName(), "name008.tnl" ), 0 );
+}*/
 #endif
 
 
diff --git a/src/UnitTests/StringTest.cpp b/src/UnitTests/StringTest.cpp
index 9b85bd728c..041c09b90e 100644
--- a/src/UnitTests/StringTest.cpp
+++ b/src/UnitTests/StringTest.cpp
@@ -8,6 +8,8 @@
 
 /* See Copyright Notice in tnl/Copyright */
 
+// Implemented by Nina Dzugasova
+
 #ifdef HAVE_GTEST 
 #include <gtest/gtest.h>
 #endif
-- 
GitLab