-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
## Features ### Open * Now returns the activeDocument after opening the file. ### JSLayer() * Removed semicolon from output. ### Document * Added FullName() which returns path to the .psd file. * Changed Filename() to DumpFile(), as Filename was misleading. * Dump function now saves the file as well, to help reduce the frequency of de-syncs. * Dump function now saves json files alongside the .psds instead of in a separate data folder- encountered issues when using the package as a module in go 1.11beta2. * Added Save() ## Testing * Added TestDocument_Save * Added TestDocument_Dump ## Misc. * Renamed pkgpath to pkgPath, to better fit go's standards. ## Fixes * DoAction now runs correctly.
- Loading branch information
Spencer
committed
Jul 25, 2018
1 parent
2f335ae
commit bf5e4f9
Showing
13 changed files
with
171 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
package ps | ||
|
||
import ( | ||
"log" | ||
"os" | ||
"path/filepath" | ||
"reflect" | ||
"runtime" | ||
"testing" | ||
) | ||
|
||
// wd is the working directory | ||
var wd string | ||
|
||
func init() { | ||
_, file, _, ok := runtime.Caller(0) | ||
if !ok { | ||
log.Fatal("runtime.Caller(0) returned !ok") | ||
} | ||
wd = filepath.Dir(file) | ||
|
||
f, err := os.Create("test.log") | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
log.SetOutput(f) | ||
} | ||
|
||
func TestDocument_Dump(t *testing.T) { | ||
// Must be true for test to be valid. | ||
Mode = Normal | ||
|
||
tests := []struct { | ||
name string | ||
}{ | ||
{"Test"}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
|
||
// Get rid of old Dump. | ||
os.Remove(filepath.Join(wd, tt.name+".json")) | ||
|
||
// Generate a fresh Doc (loaded slowly). | ||
want, err := Open(filepath.Join(wd, tt.name+".psd")) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
// Dump the contents. | ||
want.Dump() | ||
// Grab a new version of the doc (loaded from json). | ||
got, err := Open(filepath.Join(wd, tt.name+".psd")) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
got.layerSets[0].current = true | ||
if !reflect.DeepEqual(got, want) { | ||
t.Errorf("wanted: %+v\ngot: %+v", want, got) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func TestDocument_Save(t *testing.T) { | ||
file := filepath.Join(wd, "Test.psd") | ||
d, err := Open(file) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
layerName := "Group 1" | ||
lyr := d.LayerSet(layerName) | ||
if lyr == nil { | ||
t.Fatalf("LayerSet '%s' was not found", layerName) | ||
} | ||
|
||
// Change a layer name. | ||
_, err = DoJS(filepath.Join("SetName"), JSLayer(lyr.Path()), "Group 2") | ||
if err != nil { | ||
t.Error(err) | ||
} | ||
|
||
defer func() { | ||
if err := DoAction("DK", "Undo"); err != nil { | ||
t.Error(err) | ||
} | ||
err := d.Save() | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
}() | ||
|
||
err = d.Save() | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
d2, err := Open(file) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
if reflect.DeepEqual(d, d2) { | ||
t.Errorf("wanted: %+v\ngot: %+v", d, d2) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#include lib.js | ||
var stdout=newFile(arguments[0]); | ||
var obj=eval(arguments[1]); | ||
obj.name=arguments[2]; | ||
stdout.close(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.