From b7c18b51af84fb529d4aae26280dda60077ccbac Mon Sep 17 00:00:00 2001
From: DarkWiiPlayer <darkwiiplayer@hotmail.com>
Date: Wed, 10 Aug 2022 09:30:17 +0200
Subject: [PATCH] =?UTF-8?q?Write=20some=20actual=20tests=20=F0=9F=98=85?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 spec/core_spec.moon    | 36 ++++++++++++++++++++++++++++++++++--
 spec/fixtures/test     |  1 +
 spec/fixtures/test.lua |  4 ++++
 3 files changed, 39 insertions(+), 2 deletions(-)
 create mode 100644 spec/fixtures/test
 create mode 100644 spec/fixtures/test.lua

diff --git a/spec/core_spec.moon b/spec/core_spec.moon
index e8e78a9..c6ba06d 100644
--- a/spec/core_spec.moon
+++ b/spec/core_spec.moon
@@ -1,3 +1,35 @@
+import bind from require 'glass'
+
 describe 'core module', ->
-	pending 'works as intended', ->
-		-- TODO: Write some tests
+	before_each -> export config = bind 'spec/fixtures', { (require 'glass.lua') }
+
+	it 'loads configurations', ->
+		assert.equal "bar", config.test.foo
+	
+	it 'loads configurations only once', ->
+		assert.equal config.test.tab, config.test.tab
+
+	it 'loads configurations anew after deleting them', ->
+		old = config.test.tab
+		config.test = nil
+		assert.not.equal old, config.test.tab
+	
+	it 'exposes the loader list', ->
+		assert.same { (require 'glass.lua') }, config.__loaders
+	
+	it 'tries configurations in order', ->
+		txt_first = bind 'spec/fixtures', { (require 'glass.raw'), (require 'glass.lua') }
+		lua_first = bind 'spec/fixtures', { (require 'glass.lua'), (require 'glass.raw') }
+
+		assert.is.table lua_first.test
+		assert.is.string txt_first.test
+
+describe 'raw loader', ->
+	before_each -> export loader = require 'glass.raw'
+	it 'loads files as plain text', ->
+		assert.same 'plain text\n', loader 'spec/fixtures/test'
+
+describe 'lua loader', ->
+	before_each -> export loader = require 'glass.lua'
+	it 'loads Lua files', ->
+		assert.same { foo: 'bar', tab: {} }, loader 'spec/fixtures/test'
diff --git a/spec/fixtures/test b/spec/fixtures/test
new file mode 100644
index 0000000..a52e282
--- /dev/null
+++ b/spec/fixtures/test
@@ -0,0 +1 @@
+plain text
diff --git a/spec/fixtures/test.lua b/spec/fixtures/test.lua
new file mode 100644
index 0000000..b82a51f
--- /dev/null
+++ b/spec/fixtures/test.lua
@@ -0,0 +1,4 @@
+return {
+	foo = "bar";
+	tab = {};
+}