<commit_before>
should = require "should"

{parse} = require "../packetparser"


describe "packet parser", ->

  it "can parse single packet", ->

    lightPacket = new Buffer [
      1 # spec version
      , 1 # Type. 1 means light
      , 1 # light id
      , 0 # Light type. 0 means rgb
      , 0   # R
      , 255 # G
      , 0   # B
    ]

    cmds = parse lightPacket

    expexted = [
        tag: "anonymous"
      ,
        deviceType: "light"
        id: 1
        cmd:
          lightType: "rgb"
          r: 0
          g: 255
          b: 0
      ]

    should.deepEqual cmds, expexted



  it "can parse two light packets from single udp-packet", ->

    lightPacket = new Buffer [
      1 # spec version
      , 1 # Type. 1 means light
      , 1 # light id
      , 0 # Light type. 0 means rgb
      , 0 # R
      , 255 # G
      , 0 #B

      , 1 # Type. 1 means light
      , 2 # light id
      , 0 # Light type. 0 means rgb
      , 0 # R
      , 0 # G
      , 255 #B
    ]

    cmds = parse lightPacket

    expexted = [
        tag: "anonymous"
      ,
        deviceType: "light"
        id: 1
        cmd:
          lightType: "rgb"
          r: 0
          g: 255
          b: 0
      ,
        deviceType: "light"
        id: 2
        cmd:
          lightType: "rgb"
          r: 0
          g: 0
          b: 255
      ]

    should.deepEqual cmds, expexted


  it "can parse three light packets from single udp-packet", ->

    lightPacket = new Buffer [
      1 # spec version

      , 1 # Type. 1 means light
      , 1 # light id
      , 0 # Light type. 0 means rgb
      , 0 # R
      , 255 # G
      , 0 #B

      , 1 # Type. 1 means light
      , 2 # light id
      , 0 # Light type. 0 means rgb
      , 0 # R
      , 0 # G
      , 255 #B

      , 1 # Type. 1 means light
      , 3 # light id
      , 0 # Light type. 0 means rgb
      , 255 # R
      , 0 # G
      , 255 #B
    ]

    cmds = parse lightPacket

    expexted = [
        tag: "anonymous"
      ,
        deviceType: "light"
        id: 1
        cmd:
          lightType: "rgb"
          r: 0
          g: 255
          b: 0
      ,
        deviceType: "light"
        id: 2
        cmd:
          lightType: "rgb"
          r: 0
          g: 0
          b: 255
      ,
        deviceType: "light"
        id: 3
        cmd:
          lightType: "rgb"
          r: 255
          g: 0
          b: 255
      ]

    should.deepEqual cmds, expexted





  it "can have tag", ->

    lightPacket = new Buffer [
      1 # spec version

      , 0 # Tag. 0 is "device type tag"
      , 101 # e
      , 112 # p
      , 101 # e
      , 108 # l
      , 105 # i
      , 0 # end char

      , 1 # Type. 1 means light
      , 1 # light id
      , 0 # Light type. 0 means rgb
      , 0 # R
      , 255 # G
      , 0 #B

      , 1 # Type. 1 means light
      , 2 # light id
      , 0 # Light type. 0 means rgb
      , 0 # R
      , 0 # G
      , 255 #B
    ]

    cmds = parse lightPacket

    expexted = [
        tag: "epeli"
      ,
        deviceType: "light"
        id: 1
        cmd:
          lightType: "rgb"
          r: 0
          g: 255
          b: 0
      ,
        deviceType: "light"
        id: 2
        cmd:
          lightType: "rgb"
          r: 0
          g: 0
          b: 255
      ]

    should.deepEqual cmds, expexted<commit_msg>Clean up test code<commit_after>
should = require "should"

{parse} = require "../packetparser"


describe "packet parser", ->

  it "can parse single packet", ->

    lightPacket = new Buffer [
      1 # spec version
      , 1 # Type. 1 means light
      , 1 # light id
      , 0 # Light type. 0 means rgb
      , 0   # R
      , 255 # G
      , 0   # B
    ]

    should.deepEqual parse(lightPacket), [
      tag: "anonymous"
    ,
      deviceType: "light"
      id: 1
      cmd:
        lightType: "rgb"
        r: 0
        g: 255
        b: 0
    ]




  it "can parse two light packets from single udp-packet", ->

    lightPacket = new Buffer [
      1 # spec version
      , 1 # Type. 1 means light
      , 1 # light id
      , 0 # Light type. 0 means rgb
      , 0 # R
      , 255 # G
      , 0 #B

      , 1 # Type. 1 means light
      , 2 # light id
      , 0 # Light type. 0 means rgb
      , 0 # R
      , 0 # G
      , 255 #B
    ]

    should.deepEqual parse(lightPacket), [
      tag: "anonymous"
    ,
      deviceType: "light"
      id: 1
      cmd:
        lightType: "rgb"
        r: 0
        g: 255
        b: 0
    ,
      deviceType: "light"
      id: 2
      cmd:
        lightType: "rgb"
        r: 0
        g: 0
        b: 255
    ]



  it "can parse three light packets from single udp-packet", ->

    lightPacket = new Buffer [
      1 # spec version

      , 1 # Type. 1 means light
      , 1 # light id
      , 0 # Light type. 0 means rgb
      , 0 # R
      , 255 # G
      , 0 #B

      , 1 # Type. 1 means light
      , 2 # light id
      , 0 # Light type. 0 means rgb
      , 0 # R
      , 0 # G
      , 255 #B

      , 1 # Type. 1 means light
      , 3 # light id
      , 0 # Light type. 0 means rgb
      , 255 # R
      , 0 # G
      , 255 #B
    ]

    should.deepEqual parse(lightPacket), [
      tag: "anonymous"
    ,
      deviceType: "light"
      id: 1
      cmd:
        lightType: "rgb"
        r: 0
        g: 255
        b: 0
    ,
      deviceType: "light"
      id: 2
      cmd:
        lightType: "rgb"
        r: 0
        g: 0
        b: 255
    ,
      deviceType: "light"
      id: 3
      cmd:
        lightType: "rgb"
        r: 255
        g: 0
        b: 255
    ]






  it "can have tag", ->

    lightPacket = new Buffer [
      1 # spec version

      , 0 # Tag. 0 is "device type tag"
      , 101 # e
      , 112 # p
      , 101 # e
      , 108 # l
      , 105 # i
      , 0 # end char

      , 1 # Type. 1 means light
      , 1 # light id
      , 0 # Light type. 0 means rgb
      , 0 # R
      , 255 # G
      , 0 #B

      , 1 # Type. 1 means light
      , 2 # light id
      , 0 # Light type. 0 means rgb
      , 0 # R
      , 0 # G
      , 255 #B
    ]

    should.deepEqual parse(lightPacket), [
      tag: "epeli"
    ,
      deviceType: "light"
      id: 1
      cmd:
        lightType: "rgb"
        r: 0
        g: 255
        b: 0
    ,
      deviceType: "light"
      id: 2
      cmd:
        lightType: "rgb"
        r: 0
        g: 0
        b: 255
    ]

{'fraction_non_alphanumeric': 0.09973341696722597, 'fraction_numerical': 0.048298572996706916, 'mean_word_length': 1.0468549422336328, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, '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': '7223252', 'n_tokens_mistral': 2480, 'n_tokens_neox': 2097, 'n_words': 744}