package net.northing.cctp.se.util;


import net.northking.cctp.se.util.RegexUtils;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;

import java.util.Set;

@RunWith(JUnit4.class)
public class RegexUtilsTests {
    private String testData = "password of #{username} is ${pwd}";
    private String testData2 = "password of username is pwd";
    @Test
    public void testContainGlobalVar(){
        Assert.assertTrue(RegexUtils.containGlobalVar(testData));
        Assert.assertFalse(RegexUtils.containGlobalVar(testData2));
    }
    @Test
    public void testContainScriptVar(){
        Assert.assertTrue(RegexUtils.containScriptVar(testData));
        Assert.assertFalse(RegexUtils.containScriptVar(testData2));
    }
    @Test
    public void testExtractScriptVar(){
        Set<String> ret =  RegexUtils.extractScriptVar(testData);
        Assert.assertEquals(1,ret.size());
        Assert.assertTrue(ret.contains("pwd"));
        ret =  RegexUtils.extractScriptVar(testData2);
        Assert.assertEquals(0,ret.size());
    }
    @Test
    public void testExtractGlobalVar(){
        Set<String> ret =  RegexUtils.extractGlobalVar(testData);
        Assert.assertEquals(1,ret.size());
        Assert.assertTrue(ret.contains("username"));
        ret =  RegexUtils.extractGlobalVar(testData2);
        Assert.assertEquals(0,ret.size());
    }

}
