Skip to content
Open
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
1 change: 1 addition & 0 deletions slugify/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ def slugify_params(args: argparse.Namespace) -> dict[str, Any]:
save_order=args.save_order,
separator=args.separator,
stopwords=args.stopwords,
regex_pattern=args.regex_pattern,
lowercase=args.lowercase,
replacements=args.replacements,
allow_unicode=args.allow_unicode
Expand Down
12 changes: 12 additions & 0 deletions test.py
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,7 @@ class TestCommandParams(unittest.TestCase):
'save_order': False,
'separator': '-',
'stopwords': None,
'regex_pattern': None,
'lowercase': True,
'replacements': None
}
Expand Down Expand Up @@ -645,6 +646,17 @@ def test_two_text_sources_fails(self):
self.assertEqual(err.exception.code, 2)
self.assertIn("Input strings and --stdin cannot work together", cse.getvalue())

def test_regex_pattern(self):
# --regex-pattern must be passed through to slugify (issue #175).
params = self.get_params_from_cli('--regex-pattern', r'[^-a-z0-9_]+')
expected = self.make_params(regex_pattern=r'[^-a-z0-9_]+')
self.assertParamsMatch(expected, params)

def test_regex_pattern_end_to_end(self):
# The example from issue #175: underscores must survive the custom pattern.
params = self.get_params_from_cli('--regex-pattern', r'[^-a-z0-9_]+', '___This is a test___')
self.assertEqual(slugify(**params), '___this-is-a-test___')

def test_multivalued_options_with_text(self):
text = "the quick brown fox jumps over the lazy dog in a hurry"
cli_args = "--stopwords the in a hurry -- {}".format(text).split()
Expand Down