<commit_before>package com.github.tonybaines.gestalt

import spock.lang.Specification

import java.lang.reflect.Method

class ConfigSourceImplementationSpec extends Specification {
  def "Consuming a simple externally implemented config source" ( ) {
    given:
    ConfigSource mySource = new ConfigSource() {
      @Override
      def lookup(List<String> path, Method method) {
        switch(path.join('.')) {
          case 'name': return 'myConfigSource'
          case 'level': return 11
        }
      }
    }

    when: ""
    SimpleConfig config = Configurations.definedBy(SimpleConfig).from(mySource).done()

    then: ""
    config.name == 'myConfigSource'
    config.level == 11
  }

  def "Consuming a complicated externally implemented config source"() {
    given:
    ConfigSource mySource = new ConfigSource() {
      @Override
      def lookup(List<String> path, Method method) {
        switch(path.join('.')) {
          case 'subConfig.l2.level3Property': return 'Forty-two'
        }
      }<commit_msg>Spec for ConfigSource providing list types<commit_after>package com.github.tonybaines.gestalt

import spock.lang.Specification

import java.lang.reflect.Method

class ConfigSourceImplementationSpec extends Specification {

  public static final TestConfig.Thing THING_1 = ['id': '1', 'stringValue': 'thing 1'] as TestConfig.Thing
  public static final TestConfig.Thing THING_2 = ['id': '2', 'stringValue': 'thing 2'] as TestConfig.Thing

  def "Consuming a simple externally implemented config source" ( ) {
    given:
    ConfigSource mySource = new ConfigSource() {
      @Override
      def lookup(List<String> path, Method method) {
        switch(path.join('.')) {
          case 'name': return 'myConfigSource'
          case 'level': return 11
          case 'strings': return ['foo', 'bar', 'baz']
        }
      }
    }

    when: ""
    SimpleConfig config = Configurations.definedBy(SimpleConfig).from(mySource).done()

    then: ""
    config.name == 'myConfigSource'
    config.level == 11
  }

  def "Consuming a simple externally implemented config source for a list type" ( ) {
    given:
    ConfigSource mySource = new ConfigSource() {
      @Override
      def lookup(List<String> path, Method method) {
        switch(path.join('.')) {
          case 'strings': return ['foo', 'bar', 'baz']
          case 'things': return [THING_1, THING_2]
        }
      }
    }

    when: ""
    TestConfig config = Configurations.definedBy(TestConfig).from(mySource).done()

    then: ""
    config.strings.contains('foo')
    config.things.contains(THING_1)
    config.things.contains(THING_2)
  }

  def "Consuming a complicated externally implemented config source"() {
    given:
    ConfigSource mySource = new ConfigSource() {
      @Override
      def lookup(List<String> path, Method method) {
        switch(path.join('.')) {
          case 'subConfig.l2.level3Property': return 'Forty-two'
        }
      }
{'fraction_non_alphanumeric': 0.11649170335252286, 'fraction_numerical': 0.007450050795800881, 'mean_word_length': 2.933422103861518, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 8, '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': '4559190', 'n_tokens_mistral': 874, 'n_tokens_neox': 839, 'n_words': 220}