Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
ah-string-utils.cc File Reference

Tests for Ah String Utils. More...

#include <gtest/gtest.h>
#include <cmath>
#include <cstdlib>
#include <limits>
#include <random>
#include <sstream>
#include <stdexcept>
#include <vector>
#include <ah-string-utils.H>
Include dependency graph for ah-string-utils.cc:

Go to the source code of this file.

Functions

static DynList< string > reference_split_string (const string &s, const string &delim)
 Splits a string into non-empty tokens using a set of delimiter characters.
 
static void expect_tokens_eq (const DynList< string > &expected, const DynList< string > &got)
 Asserts that two DynList<string> contain the same tokens in the same order.
 
static void expect_tokens_eq (const DynList< string > &expected, const Array< string > &got)
 Assert that a DynList of strings and an Array of strings contain the same tokens.
 
 TEST (util, concat)
 
 TEST (StringUtils, vector_to_string)
 
 TEST (StringUtils, array_to_string)
 
 TEST (StringUtils, trim_variants)
 
 TEST (StringUtils, contains_string_view)
 
 TEST (StringUtils, double_formatting)
 
 TEST (StringUtils, case_conversion_ascii)
 
 TEST (StringUtils, case_conversion_non_ascii_does_not_crash)
 
 TEST (StringUtils, only_alpha_and_removals)
 
 TEST (StringUtils, join_dynlist)
 
 TEST (StringUtils, numeric_parsers)
 
 TEST (StringUtils, prefix_and_remove_prefix)
 
 TEST (StringUtils, to_name)
 
 TEST (StringUtils, split_camel_case)
 
 TEST (StringUtils, split_and_split_string)
 
 TEST (StringUtilsCritical, split_string_edge_cases)
 
 TEST (StringUtils, pascal_case)
 
 TEST (StringUtils, split_pos)
 
 TEST (StringUtils, split_n)
 
 TEST (StringUtils, complete_rows)
 
 TEST (StringUtils, format_string_no_underflow)
 
 TEST (StringUtils, format_string_csv)
 
 TEST (StringUtils, text_wrapping_and_shift)
 
 TEST (StringUtils, build_pars_list_variadic)
 
 TEST (StringUtils, build_pars_list_container)
 
 TEST (StringUtils, fill_string)
 
 TEST (StringUtils, split_to_array)
 
 TEST (StringUtils, format_string_computed_lens)
 
 TEST (StringUtilsCritical, format_string_exact_alignment_and_stream_output)
 
 TEST (StringUtils, to_string_matrix_and_lines)
 
 TEST (StringUtilsCritical, justify_text_exact_wrapping_and_margins)
 
 TEST (StringUtilsCritical, numeric_parsing_strictness)
 
 TEST (StringUtils, split_text_into_words_and_lines)
 
 TEST (StringUtils, justify_and_align_except_first)
 
 TEST (StringUtils, numeric_boundaries)
 
static int stress_multiplier ()
 
static string random_string (std::mt19937 &rng, size_t len)
 
static string random_ascii_token (std::mt19937 &rng, size_t len)
 
 TEST (StringUtilsStress, split_pos_recomposes)
 
 TEST (StringUtilsStress, split_n_recomposes)
 
 TEST (StringUtilsStress, split_string_tokens_have_no_delims)
 
 TEST (StringUtilsStress, split_string_matches_reference_parser)
 
 TEST (StringUtilsStress, case_conversion_no_crash_and_preserves_length)
 
 TEST (StringUtilsStress, build_pars_list_round_trip_for_ints)
 

Detailed Description

Tests for Ah String Utils.

Definition in file ah-string-utils.cc.

Function Documentation

◆ expect_tokens_eq() [1/2]

static void expect_tokens_eq ( const DynList< string > &  expected,
const Array< string > &  got 
)
static

Assert that a DynList of strings and an Array of strings contain the same tokens.

Compares sizes and each corresponding element; triggers test failures if the number of tokens differs or any element mismatches.

Parameters
expectedExpected tokens as a DynList<string>.
gotActual tokens as an Array<string>.

Definition at line 117 of file ah-string-utils.cc.

References Aleph::divide_and_conquer_partition_dp().

◆ expect_tokens_eq() [2/2]

static void expect_tokens_eq ( const DynList< string > &  expected,
const DynList< string > &  got 
)
static

Asserts that two DynList<string> contain the same tokens in the same order.

Compares the lists' sizes with ASSERT_EQ (which aborts the test on mismatch) and then compares each corresponding element with EXPECT_EQ.

Parameters
expectedThe expected list of tokens.
gotThe actual list of tokens to verify.

Definition at line 100 of file ah-string-utils.cc.

References Aleph::divide_and_conquer_partition_dp().

Referenced by TEST(), and TEST().

◆ random_ascii_token()

static string random_ascii_token ( std::mt19937 &  rng,
size_t  len 
)
static

Definition at line 662 of file ah-string-utils.cc.

References Aleph::divide_and_conquer_partition_dp(), and rng.

Referenced by TEST(), TEST(), and TEST().

◆ random_string()

static string random_string ( std::mt19937 &  rng,
size_t  len 
)
static

Definition at line 652 of file ah-string-utils.cc.

References Aleph::divide_and_conquer_partition_dp(), and rng.

Referenced by TEST(), TEST(), TEST(), and TEST().

◆ reference_split_string()

static DynList< string > reference_split_string ( const string &  s,
const string &  delim 
)
static

Splits a string into non-empty tokens using a set of delimiter characters.

Parameters
sInput string to split.
delimA string whose characters are treated as delimiter characters; each occurrence separates tokens. If delim is empty, the entire input is returned as a single token (unless s is empty).
Returns
DynList<string> A list of tokens where each token is a maximal substring of s that contains no characters from delim. Empty tokens are omitted.

Definition at line 63 of file ah-string-utils.cc.

References Aleph::DynList< T >::append(), and Aleph::divide_and_conquer_partition_dp().

Referenced by TEST(), and TEST().

◆ stress_multiplier()

static int stress_multiplier ( )
static

Definition at line 632 of file ah-string-utils.cc.

References Aleph::divide_and_conquer_partition_dp(), and m.

Referenced by TEST(), TEST(), TEST(), TEST(), TEST(), and TEST().

◆ TEST() [1/41]

TEST ( StringUtils  ,
array_to_string   
)

◆ TEST() [2/41]

TEST ( StringUtils  ,
build_pars_list_container   
)

◆ TEST() [3/41]

TEST ( StringUtils  ,
build_pars_list_variadic   
)

◆ TEST() [4/41]

TEST ( StringUtils  ,
case_conversion_ascii   
)

◆ TEST() [5/41]

TEST ( StringUtils  ,
case_conversion_non_ascii_does_not_crash   
)

◆ TEST() [6/41]

TEST ( StringUtils  ,
complete_rows   
)

◆ TEST() [7/41]

TEST ( StringUtils  ,
contains_string_view   
)

◆ TEST() [8/41]

TEST ( StringUtils  ,
double_formatting   
)

◆ TEST() [9/41]

TEST ( StringUtils  ,
fill_string   
)

◆ TEST() [10/41]

TEST ( StringUtils  ,
format_string_computed_lens   
)

◆ TEST() [11/41]

TEST ( StringUtils  ,
format_string_csv   
)

◆ TEST() [12/41]

TEST ( StringUtils  ,
format_string_no_underflow   
)

◆ TEST() [13/41]

TEST ( StringUtils  ,
join_dynlist   
)

◆ TEST() [14/41]

TEST ( StringUtils  ,
justify_and_align_except_first   
)

◆ TEST() [15/41]

TEST ( StringUtils  ,
numeric_boundaries   
)

◆ TEST() [16/41]

TEST ( StringUtils  ,
numeric_parsers   
)

◆ TEST() [17/41]

TEST ( StringUtils  ,
only_alpha_and_removals   
)

◆ TEST() [18/41]

TEST ( StringUtils  ,
pascal_case   
)

◆ TEST() [19/41]

TEST ( StringUtils  ,
prefix_and_remove_prefix   
)

◆ TEST() [20/41]

TEST ( StringUtils  ,
split_and_split_string   
)

◆ TEST() [21/41]

TEST ( StringUtils  ,
split_camel_case   
)

◆ TEST() [22/41]

TEST ( StringUtils  ,
split_n   
)

◆ TEST() [23/41]

TEST ( StringUtils  ,
split_pos   
)

◆ TEST() [24/41]

◆ TEST() [25/41]

TEST ( StringUtils  ,
split_to_array   
)

◆ TEST() [26/41]

TEST ( StringUtils  ,
text_wrapping_and_shift   
)

◆ TEST() [27/41]

TEST ( StringUtils  ,
to_name   
)

◆ TEST() [28/41]

TEST ( StringUtils  ,
to_string_matrix_and_lines   
)

◆ TEST() [29/41]

TEST ( StringUtils  ,
trim_variants   
)

◆ TEST() [30/41]

TEST ( StringUtils  ,
vector_to_string   
)

◆ TEST() [31/41]

TEST ( StringUtilsCritical  ,
format_string_exact_alignment_and_stream_output   
)

◆ TEST() [32/41]

TEST ( StringUtilsCritical  ,
justify_text_exact_wrapping_and_margins   
)

◆ TEST() [33/41]

TEST ( StringUtilsCritical  ,
numeric_parsing_strictness   
)

◆ TEST() [34/41]

TEST ( StringUtilsCritical  ,
split_string_edge_cases   
)

◆ TEST() [35/41]

TEST ( StringUtilsStress  ,
build_pars_list_round_trip_for_ints   
)

◆ TEST() [36/41]

TEST ( StringUtilsStress  ,
case_conversion_no_crash_and_preserves_length   
)

◆ TEST() [37/41]

TEST ( StringUtilsStress  ,
split_n_recomposes   
)

◆ TEST() [38/41]

TEST ( StringUtilsStress  ,
split_pos_recomposes   
)

◆ TEST() [39/41]

TEST ( StringUtilsStress  ,
split_string_matches_reference_parser   
)

◆ TEST() [40/41]

TEST ( StringUtilsStress  ,
split_string_tokens_have_no_delims   
)

◆ TEST() [41/41]

TEST ( util  ,
concat   
)