<commit_before>require 'spec_helper'

describe M3u8::PlaylistItem do
  it 'should initialize with hash' do
    hash = { program_id: 1, width: 1920, height: 1080, codecs: 'avc',
             bandwidth: 540, uri: 'test.url' }
    item = M3u8::PlaylistItem.new(hash)
    expect(item.program_id).to eq 1
    expect(item.width).to eq 1920
    expect(item.height).to eq 1080
    expect(item.resolution).to eq '1920x1080'
    expect(item.codecs).to eq 'avc'
    expect(item.bandwidth).to eq 540
    expect(item.uri).to eq 'test.url'
    expect(item.iframe).to be false
  end

  it 'should parse m3u8 text into instance' do
    format = %(#EXT-X-STREAM-INF:CODECS="avc",BANDWIDTH=540,) +
             %(PROGRAM-ID=1,RESOLUTION=1920x1080,) +
             %(AVERAGE-BANDWIDTH=550,AUDIO="test",VIDEO="test2",) +
             %(SUBTITLES="subs",CLOSED-CAPTIONS="caps",URI="test.url")
    item = M3u8::PlaylistItem.parse(format)
    expect(item.program_id).to eq '1'
    expect(item.codecs).to eq 'avc'
    expect(item.bandwidth).to eq 540
    expect(item.average_bandwidth).to eq 550
    expect(item.width).to eq 1920
    expect(item.height).to eq 1080
    expect(item.audio).to eq 'test'
    expect(item.video).to eq 'test2'
    expect(item.subtitles).to eq 'subs'
    expect(item.closed_captions).to eq 'caps'
    expect(item.uri).to eq 'test.url'

    format = %(#EXT-X-STREAM-INF:CODECS="avc",BANDWIDTH=540,) +
             %(PROGRAM-ID=1,AUDIO="test",VIDEO="test2",) +
             %(SUBTITLES="subs",CLOSED-CAPTIONS="caps",URI="test.url")
    item = M3u8::PlaylistItem.parse(format)
    expect(item.program_id).to eq '1'
    expect(item.codecs).to eq 'avc'
    expect(item.bandwidth).to eq 540
    expect(item.average_bandwidth).to be_nil
    expect(item.width).to be_nil
    expect(item.height).to be_nil
    expect(item.audio).to eq 'test'
    expect(item.video).to eq 'test2'
    expect(item.subtitles).to eq 'subs'
    expect(item.closed_captions).to eq 'caps'
    expect(item.uri).to eq 'test.url'
  end

  it 'should provide m3u8 format representation' do
    hash = { program_id: 1, width: 1920, height: 1080, codecs: 'avc',
             bandwidth: 540, uri: 'test.url' }
    item = M3u8::PlaylistItem.new(hash)
    output = item.to_s
    expected = '#EXT-X-STREAM-INF:PROGRAM-ID=1,RESOLUTION=1920x1080,' +
               %(CODECS="avc",BANDWIDTH=540\ntest.url)
    expect(output).to eq expected

    hash = { program_id: 1, codecs: 'avc', bandwidth: 540,
             uri: 'test.url' }
    item = M3u8::PlaylistItem.new(hash)
    output = item.to_s
    expected = '#EXT-X-STREAM-INF:PROGRAM-ID=1,' +
               %(CODECS="avc",BANDWIDTH=540\ntest.url)
    expect(output).to eq expected

    hash = { codecs: 'avc', bandwidth: 540, uri: 'test.url', audio: 'test',
             video: 'test2', average_bandwidth: 550, subtitles: 'subs',
             closed_captions: 'caps' }
    item = M3u8::PlaylistItem.new(hash)
    output = item.to_s
    expected = %(#EXT-X-STREAM-INF:CODECS="avc",BANDWIDTH=540,) +
               %(AVERAGE-BANDWIDTH=550,AUDIO="test",VIDEO="test2",) +
               %(SUBTITLES="subs",CLOSED-CAPTIONS="caps"\ntest.url)
    expect(output).to eq expected
  end

  it 'should provided m3u8 format with I-Frame option' do
    hash = { codecs: 'avc', bandwidth: 540, uri: 'test.url', iframe: true,
             video: 'test2', average_bandwidth: 550 }
    item = M3u8::PlaylistItem.new(hash)
    output = item.to_s
    expected = %(#EXT-X-I-FRAME-STREAM-INF:CODECS="avc",BANDWIDTH=540,) +
               %(AVERAGE-BANDWIDTH=550,VIDEO="test2",URI="test.url")
    expect(output).to eq expected
  end

  it 'should generate codecs string' do
    item = M3u8::PlaylistItem.new<commit_msg>Average bandwidth should not be greater than bandwidth.<commit_after>require 'spec_helper'

describe M3u8::PlaylistItem do
  it 'should initialize with hash' do
    hash = { program_id: 1, width: 1920, height: 1080, codecs: 'avc',
             bandwidth: 540, uri: 'test.url' }
    item = M3u8::PlaylistItem.new(hash)
    expect(item.program_id).to eq 1
    expect(item.width).to eq 1920
    expect(item.height).to eq 1080
    expect(item.resolution).to eq '1920x1080'
    expect(item.codecs).to eq 'avc'
    expect(item.bandwidth).to eq 540
    expect(item.uri).to eq 'test.url'
    expect(item.iframe).to be false
  end

  it 'should parse m3u8 text into instance' do
    format = %(#EXT-X-STREAM-INF:CODECS="avc",BANDWIDTH=540,) +
             %(PROGRAM-ID=1,RESOLUTION=1920x1080,) +
             %(AVERAGE-BANDWIDTH=550,AUDIO="test",VIDEO="test2",) +
             %(SUBTITLES="subs",CLOSED-CAPTIONS="caps",URI="test.url")
    item = M3u8::PlaylistItem.parse(format)
    expect(item.program_id).to eq '1'
    expect(item.codecs).to eq 'avc'
    expect(item.bandwidth).to eq 540
    expect(item.average_bandwidth).to eq 550
    expect(item.width).to eq 1920
    expect(item.height).to eq 1080
    expect(item.audio).to eq 'test'
    expect(item.video).to eq 'test2'
    expect(item.subtitles).to eq 'subs'
    expect(item.closed_captions).to eq 'caps'
    expect(item.uri).to eq 'test.url'

    format = %(#EXT-X-STREAM-INF:CODECS="avc",BANDWIDTH=540,) +
             %(PROGRAM-ID=1,AUDIO="test",VIDEO="test2",) +
             %(SUBTITLES="subs",CLOSED-CAPTIONS="caps",URI="test.url")
    item = M3u8::PlaylistItem.parse(format)
    expect(item.program_id).to eq '1'
    expect(item.codecs).to eq 'avc'
    expect(item.bandwidth).to eq 540
    expect(item.average_bandwidth).to be_nil
    expect(item.width).to be_nil
    expect(item.height).to be_nil
    expect(item.audio).to eq 'test'
    expect(item.video).to eq 'test2'
    expect(item.subtitles).to eq 'subs'
    expect(item.closed_captions).to eq 'caps'
    expect(item.uri).to eq 'test.url'
  end

  it 'should provide m3u8 format representation' do
    hash = { program_id: 1, width: 1920, height: 1080, codecs: 'avc',
             bandwidth: 540, uri: 'test.url' }
    item = M3u8::PlaylistItem.new(hash)
    output = item.to_s
    expected = '#EXT-X-STREAM-INF:PROGRAM-ID=1,RESOLUTION=1920x1080,' +
               %(CODECS="avc",BANDWIDTH=540\ntest.url)
    expect(output).to eq expected

    hash = { program_id: 1, codecs: 'avc', bandwidth: 540,
             uri: 'test.url' }
    item = M3u8::PlaylistItem.new(hash)
    output = item.to_s
    expected = '#EXT-X-STREAM-INF:PROGRAM-ID=1,' +
               %(CODECS="avc",BANDWIDTH=540\ntest.url)
    expect(output).to eq expected

    hash = { codecs: 'avc', bandwidth: 540, uri: 'test.url', audio: 'test',
             video: 'test2', average_bandwidth: 500, subtitles: 'subs',
             closed_captions: 'caps' }
    item = M3u8::PlaylistItem.new(hash)
    output = item.to_s
    expected = %(#EXT-X-STREAM-INF:CODECS="avc",BANDWIDTH=540,) +
               %(AVERAGE-BANDWIDTH=500,AUDIO="test",VIDEO="test2",) +
               %(SUBTITLES="subs",CLOSED-CAPTIONS="caps"\ntest.url)
    expect(output).to eq expected
  end

  it 'should provided m3u8 format with I-Frame option' do
    hash = { codecs: 'avc', bandwidth: 540, uri: 'test.url', iframe: true,
             video: 'test2', average_bandwidth: 550 }
    item = M3u8::PlaylistItem.new(hash)
    output = item.to_s
    expected = %(#EXT-X-I-FRAME-STREAM-INF:CODECS="avc",BANDWIDTH=540,) +
               %(AVERAGE-BANDWIDTH=550,VIDEO="test2",URI="test.url")
    expect(output).to eq expected
  end

  it 'should generate codecs string' do
    item = M3u8::PlaylistItem.new
{'fraction_non_alphanumeric': 0.15334048832841427, 'fraction_numerical': 0.04239334585457472, 'mean_word_length': 3.1532033426183843, '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': '6183503', 'n_tokens_mistral': 2989, 'n_tokens_neox': 2689, 'n_words': 516}