<commit_before>import Foundation
import Quick
import Nimble
@testable import Parchment

struct IndexPagingItem: PagingItem, Equatable {
  let index: Int
}

func ==(lhs: IndexPagingItem, rhs: IndexPagingItem) -> Bool {
  return lhs.index == rhs.index
}

class PagingStateMachineSpec: QuickSpec {
  
  override func spec() {
    
    describe("PagingStateMachineSpec") {
      
      var stateMachine: PagingStateMachine<IndexPagingItem>!
      
      beforeEach {
        stateMachine = PagingStateMachine(initialPagingItem: IndexPagingItem(index: 0))
      }
      
      it("has correct initial paging item") {
        let state: PagingState = .Current(pagingItem: IndexPagingItem(index: 0))
        expect(stateMachine.state).to(equal(state))
      }
      
      it("updates the state when the offset changes") {
        let pagingItem = IndexPagingItem(index: 0)
        let state: PagingState = .Next(pagingItem: pagingItem, upcomingPagingItem: pagingItem, offset: 0.5)
        
        stateMachine.fire(.Update(offset: 0.5))
        expect(stateMachine.state).to(equal(state))
      }

      it("doesn't update the state if offset is zero") {
        stateMachine.fire(.Update(offset: 0))
        let state: PagingState = .Current(pagingItem: IndexPagingItem(index: 0))
        expect(stateMachine.state).to(equal(state))
      }
      
      it("sets the correct state when dragging forward") {
        stateMachine.fire(.DidBeginDragging(upcomingPagingItem: IndexPagingItem(index: 2), direction: .Forward))
        let state: PagingState = .Next(pagingItem: IndexPagingItem(index: 0), upcomingPagingItem: IndexPagingItem(index: 2), offset: 0)
        expect(stateMachine.state).to(equal(state))
      }
      
      it("sets the correct state when dragging backwards") {
        stateMachine = PagingStateMachine(initialPagingItem: IndexPagingItem(index: 2))
        stateMachine.fire(.DidBeginDragging(upcomingPagingItem: IndexPagingItem(index: 0), direction: .Reverse))
        let state: PagingState = .Previous(pagingItem: IndexPagingItem(index: 2), upcomingPagingItem: IndexPagingItem(index: 0), offset: 0)
        expect(stateMachine.state).to(equal(state))
      }
      
      it("maintains the offset when beginning to drag") {
        stateMachine.fire(.Update(offset: 0.5))
        stateMachine.fire(.DidBeginDragging(upcomingPagingItem: IndexPagingItem(index: 1), direction: .Forward))
        let state: PagingState = .Next(pagingItem: IndexPagingItem(index: 0), upcomingPagingItem: IndexPagingItem(index: 1), offset: 0.5)
        expect(stateMachine.state).to(equal(state))
      }
      
      it("handles selecting an upcoming index") {
        stateMachine.fire(.Select(pagingItem: IndexPagingItem(index: 1), direction: .Forward))
        let state: PagingState = .Next(pagingItem: IndexPagingItem(index: 0), upcomingPagingItem: IndexPagingItem(index: 1), offset: 0)
        expect(stateMachine.state).to(equal(state))
      }
      
      it("handles selecting an previous index") {
        stateMachine = PagingStateMachine(initialPagingItem: IndexPagingItem(index: 1))
        stateMachine.fire(.Select(pagingItem: IndexPagingItem(index: 0), direction: .Reverse))
        let state: PagingState = .Previous(pagingItem: IndexPagingItem(index: 1), upcomingPagingItem: IndexPagingItem(index: 0), offset: 0)
        expect(stateMachine.state).to(equal(state))
      }
      
      it("handles the did move event") {
        stateMachine.fire(.DidMove(pagingItem: IndexPagingItem(index: 4)))
        let state: PagingState = .Current(pagingItem: IndexPagingItem(index: 4))
        expect(stateMachine.state).to(equal(state))
      }
      
    }
    
  }
    
}
<commit_msg>Fix failing tests after state machine refactor<commit_after>import Foundation
import Quick
import Nimble
@testable import Parchment

struct IndexPagingItem: PagingItem, Equatable {
  let index: Int
}

func ==(lhs: IndexPagingItem, rhs: IndexPagingItem) -> Bool {
  return lhs.index == rhs.index
}

class PagingStateMachineSpec: QuickSpec {
  
  override func spec() {
    
    describe("PagingStateMachineSpec") {
      
      var stateMachine: PagingStateMachine<IndexPagingItem>!
      
      beforeEach {
        stateMachine = PagingStateMachine(initialPagingItem: IndexPagingItem(index: 0))
      }
      
      it("has correct initial paging item") {
        let state: PagingState = .Current(pagingItem: IndexPagingItem(index: 0))
        expect(stateMachine.state).to(equal(state))
      }
      
      it("updates the state when the offset changes") {
        let pagingItem = IndexPagingItem(index: 0)
        let state: PagingState = .Next(pagingItem: pagingItem, upcomingPagingItem: nil, offset: 0.5)
        stateMachine.fire(.Update(offset: 0.5))
        expect(stateMachine.state).to(equal(state))
      }

      it("doesn't update the state if offset is zero") {
        stateMachine.fire(.Update(offset: 0))
        let state: PagingState = .Current(pagingItem: IndexPagingItem(index: 0))
        expect(stateMachine.state).to(equal(state))
      }
      
      it("sets the correct state when dragging forward") {
        stateMachine.fire(.DidBeginDragging(upcomingPagingItem: IndexPagingItem(index: 2), direction: .Forward))
        let state: PagingState = .Next(pagingItem: IndexPagingItem(index: 0), upcomingPagingItem: IndexPagingItem(index: 2), offset: 0)
        expect(stateMachine.state).to(equal(state))
      }
      
      it("sets the correct state when dragging backwards") {
        stateMachine = PagingStateMachine(initialPagingItem: IndexPagingItem(index: 2))
        stateMachine.fire(.DidBeginDragging(upcomingPagingItem: IndexPagingItem(index: 0), direction: .Reverse))
        let state: PagingState = .Previous(pagingItem: IndexPagingItem(index: 2), upcomingPagingItem: IndexPagingItem(index: 0), offset: 0)
        expect(stateMachine.state).to(equal(state))
      }
      
      it("maintains the offset when beginning to drag") {
        stateMachine.fire(.Update(offset: 0.5))
        stateMachine.fire(.DidBeginDragging(upcomingPagingItem: IndexPagingItem(index: 1), direction: .Forward))
        let state: PagingState = .Next(pagingItem: IndexPagingItem(index: 0), upcomingPagingItem: IndexPagingItem(index: 1), offset: 0.5)
        expect(stateMachine.state).to(equal(state))
      }
      
      it("handles selecting an upcoming index") {
        stateMachine.fire(.Select(pagingItem: IndexPagingItem(index: 1), direction: .Forward))
        let state: PagingState = .Next(pagingItem: IndexPagingItem(index: 0), upcomingPagingItem: IndexPagingItem(index: 1), offset: 0)
        expect(stateMachine.state).to(equal(state))
      }
      
      it("handles selecting an previous index") {
        stateMachine = PagingStateMachine(initialPagingItem: IndexPagingItem(index: 1))
        stateMachine.fire(.Select(pagingItem: IndexPagingItem(index: 0), direction: .Reverse))
        let state: PagingState = .Previous(pagingItem: IndexPagingItem(index: 1), upcomingPagingItem: IndexPagingItem(index: 0), offset: 0)
        expect(stateMachine.state).to(equal(state))
      }
      
      it("handles the did move event") {
        stateMachine.fire(.DidMove(pagingItem: IndexPagingItem(index: 4)))
        let state: PagingState = .Current(pagingItem: IndexPagingItem(index: 4))
        expect(stateMachine.state).to(equal(state))
      }
      
    }
    
  }
    
}

{'fraction_non_alphanumeric': 0.11115607716174289, 'fraction_numerical': 0.00971266693646297, 'mean_word_length': 3.4555288461538463, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, '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': '7547191', 'n_tokens_mistral': 2290, 'n_tokens_neox': 2187, 'n_words': 472}