<commit_before>package se.blea.flexiconf.javaapi

import org.scalatest.{FlatSpec, Matchers}
import se.blea.flexiconf
import se.blea.flexiconf._

class DirectiveSpec extends FlatSpec with Matchers {
  val arguments = List(
    flexiconf.Argument("foo", StringArgument, "string"),
    flexiconf.Argument("123", IntArgument, "int"),
    flexiconf.Argument("off", BoolArgument, "boolean"),
    flexiconf.Argument("10.1", DecimalArgument, "decimal"),
    flexiconf.Argument("100%", PercentageArgument, "percentage"),
    flexiconf.Argument("15m", DurationArgument, "duration")
  )

  val d1 = DirectiveDefinition.withName("foo").build
  val d2 = DirectiveDefinition.withName("bar").build
  val d3 = DirectiveDefinition.withName("baz")
    .withStringArg("arg1")
    .build

  val root = DirectiveDefinition.withName("directive")
    .withStringArg("string")
    .withIntArg("int")
    .withBoolArg("boolean")
    .withDecimalArg("decimal")
    .withPercentageArg("percentage")
    .withDurationArg("duration")
    .withDirectives(d1, d2, d3)
    .build

  val node1 = ConfigNode(d1, List.empty, Source("-", 0, 0))
  val node2 = ConfigNode(d2, List.empty, Source("-", 0, 0))

  val rootNode = ConfigNode(root, arguments, Source("-", 0, 0))
    .copy(children = List(node1, node2))

  val directive = new Directive(new DefaultDirective(rootNode))


  behavior of "getName"

  it should "return name" in {
    directive.getName shouldEqual "directive"
  }


  behavior of "getArgs"

  it should "return args in order" in {
    directive.getArgs.size() shouldEqual 6
    directive.getArgs.get(0).getName shouldEqual "string"
    directive.getArgs.get(1).getName shouldEqual "int"
    directive.getArgs.get(2).getName shouldEqual "boolean"
    directive.getArgs.get(3).getName shouldEqual "decimal"
    directive.getArgs.get(4).getName shouldEqual "percentage"
    directive.getArgs.get(5).getName shouldEqual "duration"
  }

  behavior of "hasDirective"

  it should "return true for existing directives" in {
    directive.contains("foo") shouldBe true
  }

  it should "return false for directives that don't exist" in {
    directive.contains("qux") shouldBe false
  }

  behavior of "getDirectives"

  it should "return java.util.List" in {
    directive.getDirectives.isInstanceOf[java.util.List[flexiconf.javaapi.Directive]] shouldBe true
  }

  it should "return wrapped directives" in {
    directive.getDirectives.size() shouldEqual 2
    directive.getDirectives.get(0).isInstanceOf[flexiconf.javaapi.Directive] shouldBe true
  }

  it should "return filtered directives in order" in {
    directive.getDirectives("foo", "baz").size() shouldEqual 1
    directive.getDirectives("foo", "baz").get(0).getName shouldEqual "foo"
  }


  behavior of "getDirective"

  it should "return a wrapped directive" in {
    directive.getDirective("foo").isInstanceOf[flexiconf.javaapi.Directive] shouldBe true
  }<commit_msg>Update test for retrieving directives in order<commit_after>package se.blea.flexiconf.javaapi

import org.scalatest.{FlatSpec, Matchers}
import se.blea.flexiconf
import se.blea.flexiconf._

class DirectiveSpec extends FlatSpec with Matchers {
  val arguments = List(
    flexiconf.Argument("foo", StringArgument, "string"),
    flexiconf.Argument("123", IntArgument, "int"),
    flexiconf.Argument("off", BoolArgument, "boolean"),
    flexiconf.Argument("10.1", DecimalArgument, "decimal"),
    flexiconf.Argument("100%", PercentageArgument, "percentage"),
    flexiconf.Argument("15m", DurationArgument, "duration")
  )

  val d1 = DirectiveDefinition.withName("foo").build
  val d2 = DirectiveDefinition.withName("bar").build
  val d3 = DirectiveDefinition.withName("baz")
    .withStringArg("arg1")
    .build

  val root = DirectiveDefinition.withName("directive")
    .withStringArg("string")
    .withIntArg("int")
    .withBoolArg("boolean")
    .withDecimalArg("decimal")
    .withPercentageArg("percentage")
    .withDurationArg("duration")
    .withDirectives(d1, d2, d3)
    .build

  val node1 = ConfigNode(d1, List.empty, Source("-", 0, 0))
  val node2 = ConfigNode(d2, List.empty, Source("-", 0, 0))

  val rootNode = ConfigNode(root, arguments, Source("-", 0, 0))
    .copy(children = List(node1, node2))

  val directive = new Directive(new DefaultDirective(rootNode))


  behavior of "getName"

  it should "return name" in {
    directive.getName shouldEqual "directive"
  }


  behavior of "getArgs"

  it should "return args in order" in {
    directive.getArgs.size() shouldEqual 6
    directive.getArgs.get(0).getName shouldEqual "string"
    directive.getArgs.get(1).getName shouldEqual "int"
    directive.getArgs.get(2).getName shouldEqual "boolean"
    directive.getArgs.get(3).getName shouldEqual "decimal"
    directive.getArgs.get(4).getName shouldEqual "percentage"
    directive.getArgs.get(5).getName shouldEqual "duration"
  }

  behavior of "hasDirective"

  it should "return true for existing directives" in {
    directive.contains("foo") shouldBe true
  }

  it should "return false for directives that don't exist" in {
    directive.contains("qux") shouldBe false
  }

  behavior of "getDirectives"

  it should "return java.util.List" in {
    directive.getDirectives.isInstanceOf[java.util.List[flexiconf.javaapi.Directive]] shouldBe true
  }

  it should "return wrapped directives" in {
    directive.getDirectives.size() shouldEqual 2
    directive.getDirectives.get(0).isInstanceOf[flexiconf.javaapi.Directive] shouldBe true
  }

  it should "return filtered directives in order" in {
    directive.getDirectives("foo", "bar").size() shouldEqual 2
    directive.getDirectives("foo", "bar").get(0).getName shouldEqual "foo"
    directive.getDirectives("foo", "bar").get(1).getName shouldEqual "bar"
  }


  behavior of "getDirective"

  it should "return a wrapped directive" in {
    directive.getDirective("foo").isInstanceOf[flexiconf.javaapi.Directive] shouldBe true
  }
{'fraction_non_alphanumeric': 0.12411467116357504, 'fraction_numerical': 0.013996627318718381, 'mean_word_length': 4.401639344262295, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6544173', 'n_tokens_mistral': 1951, 'n_tokens_neox': 1853, 'n_words': 430}