From 1765b40ad17be4a9250b78cbe8a34117c7e8ed3c Mon Sep 17 00:00:00 2001
From: Anton Sarukhanov <code@ant.sr>
Date: Wed, 11 Dec 2019 22:06:03 -0500
Subject: [PATCH] Add some tests.

---
 .gitlab-ci.yml                    |  6 ++++-
 tests/__init__.py                 |  0
 tests/util/__init__.py            |  0
 tests/util/test_whatdateformat.py | 45 +++++++++++++++++++++++++++++++
 4 files changed, 50 insertions(+), 1 deletion(-)
 create mode 100644 tests/__init__.py
 create mode 100644 tests/util/__init__.py
 create mode 100644 tests/util/test_whatdateformat.py

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 80b4325..dcc7891 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -3,10 +3,14 @@ image: python:3-buster
 before_script:
   - pip install -r requirements-dev.txt
 
-test:
+analyze:
     script:
     - bandit whatformat/*.py whatformat/util/*.py
     - flake8 --config=.flake8 whatformat/*.py whatformat/util/*.py
     - mypy whatformat/*.py whatformat/util/*.py
     - pydocstyle whatformat/*.py whatformat/util/*.py
     - pylint whatformat/*.py whatformat/util/*.py
+
+test:
+    script:
+    - python3 -m unittest
diff --git a/tests/__init__.py b/tests/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/tests/util/__init__.py b/tests/util/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/tests/util/test_whatdateformat.py b/tests/util/test_whatdateformat.py
new file mode 100644
index 0000000..1db22d6
--- /dev/null
+++ b/tests/util/test_whatdateformat.py
@@ -0,0 +1,45 @@
+"""Tests for util.whatdateformat."""
+
+import unittest
+from whatformat.util.whatdateformat import get_unique_format_strings
+
+
+class WhatDateFormatTests(unittest.TestCase):
+    """Tests for util.whatdateformat."""
+
+    def test_get_unique_format_strings(self):
+        """Test for util.whatdateformat.get_unique_format_strings()."""
+        cases = [
+            ('Jan 2', ['%b %-d']),
+            ('Jan 15', ['%b %d']),
+            ('1-2-1999', ['%-m-%-d-%Y']),
+            ('1.2.1999', ['%-m.%-d.%Y']),
+            ('1.2.1999.', ['%-m.%-d.%Y.']),
+            ('1/2/1999', ['%-m/%-d/%Y']),
+            ('1999.1.2', ['%Y.%-m.%-d']),
+            ('1999-1-2', ['%Y-%-m-%-d']),
+            ('1999. 2. 1', ['%Y. %-m. %-d']),
+            ('1999.2.1', ['%Y.%-m.%-d']),
+            ('1999/2/1', ['%Y/%-m/%-d']),
+            ('28-11-1999', ['%d-%m-%Y']),
+            ('28.11.1999', ['%d.%m.%Y']),
+            ('28.11.1999.', ['%d.%m.%Y.']),
+            ('28/11/1999', ['%d/%m/%Y']),
+            ('11.28.1999', ['%m.%d.%Y']),
+            ('11/28/1999', ['%m/%d/%Y']),
+            ('11-28-1999', ['%m-%d-%Y']),
+            ('1-28-1999', ['%-m-%d-%Y']),
+            ('1.28.1999', ['%-m.%d.%Y']),
+            ('1.28.1999.', ['%-m.%d.%Y.']),
+            ('1/28/1999', ['%-m/%d/%Y']),
+            ('11-28-1999', ['%m-%d-%Y']),
+            ('11/28/1999', ['%m/%d/%Y']),
+            ('1999-11-28', ['%Y-%m-%d']),
+            ('1999.11.28.', ['%Y.%m.%d.']),
+            ('1999/11/28', ['%Y/%m/%d']),
+            ('ayy lmao', []),
+            ('', []),
+        ]
+        for (date, formats) in cases:
+            self.assertEqual(set(get_unique_format_strings(date)),
+                             set(formats))
-- 
GitLab