PHP Classes

File: prefix_test.go

Recommend this page to a friend!
  Classes of Wolfy-J  >  goridge  >  prefix_test.go  >  Download  
File: prefix_test.go
Role: Auxiliary data
Content type: text/plain
Description: Auxiliary data
Class: goridge
Run Golang code from PHP calling its RPC server
Author: By
Last change:
Date: 3 years ago
Size: 1,543 bytes
 

Contents

Class file image Download
package goridge

import (
	"bytes"
	"github.com/stretchr/testify/assert"
	"testing"
)

func TestNewPrefix(t *testing.T) {
	p1 := NewPrefix()

	assert.Equal(t, byte(0), p1.Flags())
	assert.Equal(t, uint64(0), p1.Size())
}

func TestPrefix_WithFlag(t *testing.T) {
	p1 := NewPrefix()
	p2 := p1.WithFlag(PayloadRaw)

	assert.False(t, p1.HasFlag(PayloadRaw))
	assert.True(t, p2.HasFlag(PayloadRaw))

	p3 := p2.WithFlag(PayloadEmpty)
	assert.True(t, p3.HasFlag(PayloadRaw))
	assert.True(t, p3.HasFlag(PayloadEmpty))
}

func TestPrefix_WithFlags(t *testing.T) {
	p1 := NewPrefix().WithFlag(PayloadRaw)
	p2 := p1.WithFlags(PayloadEmpty)

	assert.False(t, p2.HasFlag(PayloadRaw))
	assert.True(t, p2.HasFlag(PayloadEmpty))
}

func TestPrefix_WithSize(t *testing.T) {
	p1 := NewPrefix().WithFlag(PayloadRaw)
	p2 := p1.WithSize(1000)

	assert.True(t, p1.HasFlag(PayloadRaw))
	assert.Equal(t, uint64(0), p1.Size())

	assert.True(t, p2.HasFlag(PayloadRaw))
	assert.Equal(t, uint64(1000), p2.Size())
}

func TestPrefix_HasPayload(t *testing.T) {
	p1 := NewPrefix().WithFlag(PayloadRaw)
	p2 := p1.WithSize(1000)

	assert.False(t, p1.HasPayload())
	assert.True(t, p2.HasPayload())

	p3 := p2.WithFlag(PayloadEmpty)
	assert.False(t, p3.HasPayload())
}

func TestReadPrefix(t *testing.T) {
	buffer := bytes.NewBuffer([]byte{PayloadRaw | PayloadControl, 255, 0, 0, 0, 255, 0, 0, 0})

	p1 := NewPrefix()
	buffer.Read(p1[:])

	assert.True(t, p1.HasFlag(PayloadRaw))
	assert.True(t, p1.HasFlag(PayloadControl))

	assert.Equal(t, uint64(1095216660735), p1.Size())
}
For more information send a message to info at phpclasses dot org.