<commit_before>const render = require('../../render')
const test = require('tape')
// const parse = require('parse-element')
const s = require('brisky-struct')
// const strip = require('strip-formatting')

test('switch - basic', t => {
  const state = s({ field: { navigation: {} } })
  const app = render(
    {
      types: {
        switcher: {
          $: '$switch',
          $switch: (s, subs, tree, key) => {
            if (s.compute() > 1) {
              return subs.props[key].self
            }
          },
          text: { $: true }
        },
        spesh: {
          text: 'SPESH',
          $: 'root.items.$any',
          props: {
            default: { type: 'switcher' }
          }
        }
      },
      blax: { type: 'spesh' },
      blurf: { $: 'root.items.$any', props: { default: { type: 'element', text: '!!!' } } },
      bla: { type: 'spesh' },
      holder: {
        text: { $: 'navigation', $transform: val => '🦄 switcher! ' + val },
        switcher: {
          $switch: (state, subs, tree, key) => {
            if (state.compute() === 100) {
              return false
            } else if (state.compute() === 2) {
              return subs.props[key].any
            } else if (state.compute() !== 0) {
              return subs.props[key].self
            }
          },
          $: 'navigation.$switch',
          text: { $: true, $transform: val => val + ' switch' },
          props: {
            any: { type: 'spesh' }
          }
        },
        bla: {
          text: { $: 'navigation', $transform: val => val + '?' }
        }
      }
    },
    state,
    (subs, tree) => {
      console.log('SUBS:', subs, 'TREE:', tree)
    }
  )

  state.set({
    items: [ 1, 2, 3, 4 ],
    navigation: [ '@', 'root', 'items', 0 ]
  })

  var cnt = 0
  const defer = val => new Promise(
    resolve => setTimeout(() => resolve(val), ++cnt * 1000)
  )

  state.set(defer({ items: [ 100 ] }))
  state.set(defer({ items: [ 2 ] }))
  state.set(defer({ items: [ 0 ] }))
  state.set(defer({ items: state.items.map(val => 0) }))

  if (document.body) {
    document.body.appendChild(app)
  }

  t.end()
})<commit_msg>more tests<commit_after>const render = require('../../render')
const test = require('tape')
// const parse = require('parse-element')
const s = require('brisky-struct')
// const strip = require('strip-formatting')

test('switch - basic', t => {
  const state = s({ field: { navigation: {} } })
  const app = render(
    {
      types: {
        switcher: {
          $: '$switch',
          $switch: (s, subs, tree, key) => {
            if (s.compute() > 1) {
              return subs.props[key].self
            }
          },
          text: { $: true }
        },
        spesh: {
          text: 'SPESH',
          $: 'root.items.$any',
          props: {
            default: { type: 'switcher' }
          }
        }
      },
      blax: { type: 'spesh' },
      blurf: { $: 'root.items.$any', props: { default: { type: 'element', text: '!!!' } } },
      bla: { type: 'spesh' },
      holder: {
        text: { $: 'navigation', $transform: val => '🦄 switcher! ' + val },
        switcher: {
          $switch: (state, subs, tree, key) => {
            if (state.compute() === 100) {
              return false
            } else if (state.compute() === 2) {
              return subs.props[key].any
            } else if (state.compute() !== 0) {
              return subs.props[key].self
            }
          },
          $: 'navigation.$switch',
          text: { $: true, $transform: val => val + ' SWITCH IT SELF' },
          props: {
            any: { type: 'spesh' }
          }
        },
        bla: {
          text: { $: 'navigation', $transform: val => val + '?' }
        }
      }
    },
    state,
    (subs, tree) => {
      console.log('SUBS:', subs, 'TREE:', tree)
    }
  )

  state.set({
    items: [ 1, 2, 3, 4 ],
    navigation: [ '@', 'root', 'items', 0 ]
  })

  var cnt = 0
  const defer = val => new Promise(
    resolve => setTimeout(() => resolve(val), ++cnt * 500)
  )

  state.set(defer({ items: [ 100 ] }))
  state.set(defer({ items: [ 2 ] }))
  state.set(defer({ items: [ 0 ] }))
  state.set(defer({ items: state.items.map(val => 0) }))
  state.set(defer({ items: state.items.map((val, key) => key) }))
  state.set(defer({ items: [ 2 ] }))
  state.set(defer({ navigation: '🦄' }))
  state.set(defer({ navigation: 0 }))

  if (document.body) {
    document.body.appendChild(app)
  }

  t.end()
})
{'fraction_non_alphanumeric': 0.19790971758950412, 'fraction_numerical': 0.01000667111407605, 'mean_word_length': 1.698260347930414, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 28, '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': '6499059', 'n_tokens_mistral': 1534, 'n_tokens_neox': 1474, 'n_words': 331}