cortana test

This commit is contained in:
Sola
2016-04-18 16:18:50 +08:00
parent 81a52327fe
commit 1e18bc3179
3 changed files with 48 additions and 5 deletions

View File

@@ -1,5 +1,6 @@
package love.sola.netsupport.config; package love.sola.netsupport.config;
import lombok.Data;
import org.yaml.snakeyaml.Yaml; import org.yaml.snakeyaml.Yaml;
import java.io.InputStream; import java.io.InputStream;
@@ -15,19 +16,27 @@ import java.util.regex.Pattern;
*/ */
public class Cortana { public class Cortana {
public static List<Compiled> entries; public static List<Compiled> entries;
public static void load() { public static void load() {
InputStream in = Lang.class.getClassLoader().getResourceAsStream("cortana.yml"); InputStream in = Lang.class.getClassLoader().getResourceAsStream("cortana.yml");
Map<String, Object> root = (Map<String, Object>) new Yaml().load(in); RawConfig root = new Yaml().loadAs(in, RawConfig.class);
} }
static class Compiled {
public static class Compiled {
Pattern[] patterns; Pattern[] patterns;
String[] replies; String[] replies;
} }
@Data
public static class Rule {
String[] regexp;
String[] replies;
}
@Data
public static class RawConfig {
Map<String, Rule> rules;
}
} }

View File

@@ -0,0 +1,18 @@
package love.sola.netsupport.config;
import org.junit.Test;
/**
* ***********************************************
* Created by Sola on 2016/4/18.
* Don't modify this source without my agreement
* ***********************************************
*/
public class CortanaTest {
@Test
public void load() throws Exception {
Cortana.load();
}
}

View File

@@ -0,0 +1,16 @@
rules:
rule1:
regexp:
- 'single test'
replies:
- 'single test'
rule2:
regexp: ['inline test', 'inline test']
replies: ['inline test', 'inline test']
rule3:
regexp:
- 'multi line test'
- 'multi line test'
replies:
- 'multi line test'
- 'multi line test'