File: string_utils_spec.rb

package info (click to toggle)
ruby-nori 2.7.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 244 kB
  • sloc: ruby: 1,146; xml: 266; makefile: 2
file content (33 lines) | stat: -rw-r--r-- 1,072 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
require "spec_helper"

describe Nori::StringUtils do

  describe ".snakecase" do
    it "lowercases one word CamelCase" do
      expect(Nori::StringUtils.snakecase("Merb")).to eq("merb")
    end

    it "makes one underscore snakecase two word CamelCase" do
      expect(Nori::StringUtils.snakecase("MerbCore")).to eq("merb_core")
    end

    it "handles CamelCase with more than 2 words" do
      expect(Nori::StringUtils.snakecase("SoYouWantContributeToMerbCore")).to eq("so_you_want_contribute_to_merb_core")
    end

    it "handles CamelCase with more than 2 capital letter in a row" do
      expect(Nori::StringUtils.snakecase("CNN")).to eq("cnn")
      expect(Nori::StringUtils.snakecase("CNNNews")).to eq("cnn_news")
      expect(Nori::StringUtils.snakecase("HeadlineCNNNews")).to eq("headline_cnn_news")
    end

    it "does NOT change one word lowercase" do
      expect(Nori::StringUtils.snakecase("merb")).to eq("merb")
    end

    it "leaves snake_case as is" do
      expect(Nori::StringUtils.snakecase("merb_core")).to eq("merb_core")
    end
  end

end