From d0f57db0aa7a67da7685651acde24e814d6ab2f1 Mon Sep 17 00:00:00 2001
From: Gabriel Arazas <foodogsquared@foodogsquared.one>
Date: Sat, 24 Feb 2024 18:48:07 +0800
Subject: [PATCH] bahaghari/tests/lib: init

---
 subprojects/bahaghari/tests/default.nix       |   8 ++
 subprojects/bahaghari/tests/lib/default.nix   |   9 ++
 .../tests/lib/tinted-theming/default.nix      |  17 +++
 .../tinted-theming/sample-base16-scheme.yml   |  22 ++++
 .../tinted-theming/sample-base24-scheme.yml   |  29 +++++
 .../bahaghari/tests/lib/trivial/default.nix   | 109 ++++++++++++++++++
 .../bahaghari/tests/lib/trivial/simple.yml    |   7 ++
 7 files changed, 201 insertions(+)
 create mode 100644 subprojects/bahaghari/tests/default.nix
 create mode 100644 subprojects/bahaghari/tests/lib/default.nix
 create mode 100644 subprojects/bahaghari/tests/lib/tinted-theming/default.nix
 create mode 100644 subprojects/bahaghari/tests/lib/tinted-theming/sample-base16-scheme.yml
 create mode 100644 subprojects/bahaghari/tests/lib/tinted-theming/sample-base24-scheme.yml
 create mode 100644 subprojects/bahaghari/tests/lib/trivial/default.nix
 create mode 100644 subprojects/bahaghari/tests/lib/trivial/simple.yml

diff --git a/subprojects/bahaghari/tests/default.nix b/subprojects/bahaghari/tests/default.nix
new file mode 100644
index 00000000..a151c1a9
--- /dev/null
+++ b/subprojects/bahaghari/tests/default.nix
@@ -0,0 +1,8 @@
+# This is the unit cases for our Nix project.
+{ pkgs ? import <nixpkgs> { } }:
+
+
+{
+  lib = import ./lib { inherit pkgs; };
+  #modules = import ./modules { inherit pkgs; };
+}
diff --git a/subprojects/bahaghari/tests/lib/default.nix b/subprojects/bahaghari/tests/lib/default.nix
new file mode 100644
index 00000000..7283d4d8
--- /dev/null
+++ b/subprojects/bahaghari/tests/lib/default.nix
@@ -0,0 +1,9 @@
+{ pkgs }:
+
+let
+  lib = import ../../lib { inherit pkgs; };
+in
+{
+  trivial = import ./trivial { inherit pkgs lib; };
+  tinted-theming = import ./tinted-theming { inherit pkgs lib; };
+}
diff --git a/subprojects/bahaghari/tests/lib/tinted-theming/default.nix b/subprojects/bahaghari/tests/lib/tinted-theming/default.nix
new file mode 100644
index 00000000..27d49d52
--- /dev/null
+++ b/subprojects/bahaghari/tests/lib/tinted-theming/default.nix
@@ -0,0 +1,17 @@
+{ pkgs, lib }:
+
+let
+  sampleBase16Scheme = lib.trivial.importYAML ./sample-base16-scheme.yml;
+  sampleBase24Scheme = lib.trivial.importYAML ./sample-base24-scheme.yml;
+in
+pkgs.lib.runTests {
+  testIsBase16 = {
+    expr = lib.tinted-theming.isBase16 sampleBase16Scheme.palette;
+    expected = true;
+  };
+
+  testIsBase24 = {
+    expr = lib.tinted-theming.isBase24 sampleBase24Scheme.palette;
+    expected = true;
+  };
+}
diff --git a/subprojects/bahaghari/tests/lib/tinted-theming/sample-base16-scheme.yml b/subprojects/bahaghari/tests/lib/tinted-theming/sample-base16-scheme.yml
new file mode 100644
index 00000000..09f1a221
--- /dev/null
+++ b/subprojects/bahaghari/tests/lib/tinted-theming/sample-base16-scheme.yml
@@ -0,0 +1,22 @@
+system: "base16"
+name: "Bark on a tree"
+author: "Gabriel Arazas (https://foodogsquared.one)"
+variant: "dark"
+description: "Rusty theme resembling forestry inspired from Nord theme."
+palette:
+  base00: "2b221f"
+  base01: "412c26"
+  base02: "5c362c"
+  base03: "a45b43"
+  base04: "e1bcb2"
+  base05: "f5ecea"
+  base06: "fefefe"
+  base07: "eb8a65"
+  base08: "d03e68"
+  base09: "df937a"
+  base0A: "afa644"
+  base0B: "85b26e"
+  base0C: "eb914a"
+  base0D: "c67f62"
+  base0E: "8b7ab9"
+  base0F: "7f3F83"
diff --git a/subprojects/bahaghari/tests/lib/tinted-theming/sample-base24-scheme.yml b/subprojects/bahaghari/tests/lib/tinted-theming/sample-base24-scheme.yml
new file mode 100644
index 00000000..1c479599
--- /dev/null
+++ b/subprojects/bahaghari/tests/lib/tinted-theming/sample-base24-scheme.yml
@@ -0,0 +1,29 @@
+system: "base24"
+name: "Flat"
+author: "FredHappyface (https://github.com/fredHappyface)"
+variant: "dark"
+palette:
+  base00: "082845"
+  base01: "1d2845"
+  base02: "2e2e45"
+  base03: "444e5b"
+  base04: "68717b"
+  base05: "8c939a"
+  base06: "b0b6ba"
+  base07: "e7eced"
+  base08: "a82320"
+  base09: "e58d11"
+  base0A: "3c7dd2"
+  base0B: "2d9440"
+  base0C: "2c9370"
+  base0D: "3167ac"
+  base0E: "781aa0"
+  base0F: "541110"
+  base10: "002240"
+  base11: "001629"
+  base12: "d4312e"
+  base13: "e5be0c"
+  base14: "32a548"
+  base15: "35b387"
+  base16: "3c7dd2"
+  base17: "8230a7"
diff --git a/subprojects/bahaghari/tests/lib/trivial/default.nix b/subprojects/bahaghari/tests/lib/trivial/default.nix
new file mode 100644
index 00000000..ba422934
--- /dev/null
+++ b/subprojects/bahaghari/tests/lib/trivial/default.nix
@@ -0,0 +1,109 @@
+{ pkgs, lib }:
+
+let
+  customOctalGlyphs = {
+    "0" = "A";
+    "1" = "B";
+    "2" = "C";
+    "3" = "D";
+    "4" = "E";
+    "5" = "F";
+    "6" = "G";
+    "7" = "H";
+  };
+
+  customBase24Glyphs = {
+    "0" = "0";
+    "1" = "1";
+    "2" = "2";
+    "3" = "3";
+    "4" = "4";
+    "5" = "5";
+    "6" = "6";
+    "7" = "7";
+    "8" = "8";
+    "9" = "9";
+    "10" = "A";
+    "11" = "B";
+    "12" = "C";
+    "13" = "D";
+    "14" = "E";
+    "15" = "F";
+    "16" = "G";
+    "17" = "H";
+    "18" = "I";
+    "19" = "J";
+    "20" = "M";
+    "21" = "N";
+    "22" = "O";
+    "23" = "P";
+  };
+in
+pkgs.lib.runTests {
+  testBaseDigitWithCustomOctalGlyph = {
+    expr = lib.trivial.toBaseDigitsWithGlyphs 8 9 customOctalGlyphs;
+    expected = "BB";
+  };
+
+  testBaseDigitWithCustomOctalGlyph2 = {
+    expr = lib.trivial.toBaseDigitsWithGlyphs 8 641 customOctalGlyphs;
+    expected = "BCAB";
+  };
+
+  testBaseDigitWithProperBase24Glyph = {
+    expr = lib.trivial.toBaseDigitsWithGlyphs 24 641 customBase24Glyphs;
+    expected = "12H";
+  };
+
+  testBaseDigitWithProperBase24Glyph2 = {
+    expr = lib.trivial.toBaseDigitsWithGlyphs 24 2583 customBase24Glyphs;
+    expected = "4BF";
+  };
+
+  # We're mainly testing if the underlying YAML library is mostly compliant
+  # with whatever it claims.
+  testImportBasicYAML = {
+    expr = lib.trivial.importYAML ./simple.yml;
+    expected = {
+      hello = "there";
+      how-are-you-doing = "I'm fine. Thank you for asking.\n";
+      "It's a number" = 53;
+      dog-breeds = [ "chihuahua" "golden retriever" ];
+    };
+  };
+
+  testImportTintedThemingBase16YAML = {
+    expr = lib.trivial.importYAML ../tinted-theming/sample-base16-scheme.yml;
+    expected = {
+      system = "base16";
+      name = "Bark on a tree";
+      author = "Gabriel Arazas (https://foodogsquared.one)";
+      description = "Rusty theme resembling forestry inspired from Nord theme.";
+      variant = "dark";
+      palette = {
+        base00 = "2b221f";
+        base01 = "412c26";
+        base02 = "5c362c";
+        base03 = "a45b43";
+        base04 = "e1bcb2";
+        base05 = "f5ecea";
+        base06 = "fefefe";
+        base07 = "eb8a65";
+        base08 = "d03e68";
+        base09 = "df937a";
+        base0A = "afa644";
+        base0B = "85b26e";
+        base0C = "eb914a";
+        base0D = "c67f62";
+        base0E = "8b7ab9";
+        base0F = "7f3F83";
+      };
+    };
+  };
+
+  # YAML is a superset of JSON (or was it the other way around?) after v1.2.
+  testToYAML = {
+    expr = lib.trivial.toYAML { } { hello = "there"; };
+    expected = "{\"hello\":\"there\"}";
+  };
+}
diff --git a/subprojects/bahaghari/tests/lib/trivial/simple.yml b/subprojects/bahaghari/tests/lib/trivial/simple.yml
new file mode 100644
index 00000000..86cda616
--- /dev/null
+++ b/subprojects/bahaghari/tests/lib/trivial/simple.yml
@@ -0,0 +1,7 @@
+hello: there
+how-are-you-doing: |
+  I'm fine. Thank you for asking.
+It's a number: 53
+dog-breeds:
+  - chihuahua
+  - golden retriever