test: Initial unit testing
- Test quests vector loading - Test default quest on empty fields - Test correct quest - Fixed config paths handling
This commit is contained in:
parent
a5eac1b64f
commit
94d771107d
7 changed files with 102 additions and 15 deletions
10
tests/cfg/config.toml
Normal file
10
tests/cfg/config.toml
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
# Default config
|
||||
|
||||
# Path to quests folder relative to config
|
||||
quests_path = "quests"
|
||||
|
||||
# Path to accounts folder relative to config
|
||||
accounts_path = "accounts"
|
||||
|
||||
# Path to map .toml file relative to config
|
||||
map = "map.toml"
|
||||
2
tests/cfg/quests/0.toml
Normal file
2
tests/cfg/quests/0.toml
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
# This example demonstrates that empty quests will be loaded correctly with default values
|
||||
# see main.rs
|
||||
8
tests/cfg/quests/1.toml
Normal file
8
tests/cfg/quests/1.toml
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
# This example demonstrates typical quest
|
||||
# see main.rs
|
||||
id = 1
|
||||
difficulty = "Easy"
|
||||
reward = 100
|
||||
name = "Example easy quest"
|
||||
description = "Answer this quest without any attachments or comments"
|
||||
answer = "Accept the answer if it has no attachments and an empty comment"
|
||||
8
tests/cfg/quests/2.toml
Normal file
8
tests/cfg/quests/2.toml
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
# This example demonstrates incorrect quest which will not be loaded from config
|
||||
# see main.rs
|
||||
id = 133713371337
|
||||
difficulty = sick
|
||||
reward = an infinite amount of coffee
|
||||
name = "Impossible quest"
|
||||
description = "This quest won't be loaded in the game, therefore you can't solve it"
|
||||
answer = 42
|
||||
40
tests/main.rs
Normal file
40
tests/main.rs
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
use squad_quest::{config::Config, quest::Quest};
|
||||
|
||||
#[test]
|
||||
fn load_quests() {
|
||||
let config = Config::load("./tests/cfg/config.toml".into());
|
||||
let quests = config.load_quests();
|
||||
|
||||
assert_eq!(quests.len(), 2);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn empty_quest_is_default() {
|
||||
// First loaded quest should be 0.toml, which is empty
|
||||
let config = Config::load("./tests/cfg/config.toml".into());
|
||||
let mut quests = config.load_quests();
|
||||
quests.sort_by(|a,b| a.id.cmp(&b.id));
|
||||
let quest = quests.first().unwrap();
|
||||
|
||||
let default = Quest::default();
|
||||
|
||||
assert_eq!(*quest, default);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn quest_one() {
|
||||
let config = Config::load("./tests/cfg/config.toml".into());
|
||||
let quests = config.load_quests();
|
||||
let quest = quests.iter().find(|q| q.id == 1).unwrap();
|
||||
|
||||
let expected = Quest {
|
||||
id: 1,
|
||||
difficulty: squad_quest::quest::QuestDifficulty::Easy,
|
||||
reward: 100,
|
||||
name: "Example easy quest".to_owned(),
|
||||
description: "Answer this quest without any attachments or comments".to_owned(),
|
||||
answer: "Accept the answer if it has no attachments and an empty comment".to_owned()
|
||||
};
|
||||
|
||||
assert_eq!(*quest, expected);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue