Skip to content

Add tests for FastExcel.lxw_time #105

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions .octocov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,12 @@ diff:
datastores:
- artifact://${GITHUB_REPOSITORY}
comment:
if: is_pull_request
deletePrevious: true
if: false
body:
if: true
#comment:
# if: is_pull_request
# deletePrevious: true
report:
if: is_default_branch
datastores:
Expand Down
11 changes: 4 additions & 7 deletions lib/fast_excel.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
require_relative './fast_excel/binding'
require 'set'

# not used for now
#require_relative '../ext/fast_excel/text_width_ext'

module FastExcel

class Formula
Expand Down Expand Up @@ -295,8 +292,8 @@ def self.color_to_hex(value)
return EXTRA_COLORS[value.to_sym]
elsif COLOR_ENUM.find(value.to_sym)
return COLOR_ENUM.find(value.to_sym)
elsif COLOR_ENUM.find("color_#{value.to_sym}")
return COLOR_ENUM.find("color_#{value.to_sym}")
elsif COLOR_ENUM.find("color_#{value}".to_sym)
return COLOR_ENUM.find("color_#{value}".to_sym)
elsif value =~ /^#?(0x)?([\da-f]){6}$/i
value = value.sub('#', '') if value.start_with?('#')
return value.start_with?('0x') ? value.to_i(16) : "0x#{value}".to_i(16)
Expand Down Expand Up @@ -334,8 +331,8 @@ def fields_hash
res
end

def pretty_print(pp)
pp fields_hash
def pretty_print(pp_obj)
fields_hash.pretty_print(pp_obj)
end
end

Expand Down
4 changes: 4 additions & 0 deletions sonar-project.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
sonar.sources=.
sonar.language=ruby
sonar.ruby.coverage.reportPaths=coverage/.resultset.json
sonar.exclusions=**/*_test.rb,**/coverage/**
15 changes: 15 additions & 0 deletions test/color_to_hex_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
require_relative 'test_helper'

describe "FastExcel.color_to_hex" do
it "should convert hex number color to hex" do
assert_equal(FastExcel.color_to_hex(0xFF0000), 0xFF0000)
end

it "should convert color name to hex" do
assert_equal(FastExcel.color_to_hex("color_lime"), 0x00FF00)
end

it "should convert color name (extra colors) to hex" do
assert_equal(FastExcel.color_to_hex("steel_blue"), 0x4682B4)
end
end
14 changes: 14 additions & 0 deletions test/date_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,17 @@
end

end

describe "FastExcel.lxw_time" do
it "should make Libxlsxwriter::Datetime" do
time = Time.at(610421163).utc
lxw_time = FastExcel.lxw_time(time)

assert_equal(lxw_time[:year], 1989)
assert_equal(lxw_time[:month], 5)
assert_equal(lxw_time[:day], 6)
assert_equal(lxw_time[:hour], 1)
assert_equal(lxw_time[:min], 26)
assert_equal(lxw_time[:sec], 3.0)
end
end